Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to Get Transaction Record Receiver #220

Open
Cecil-cc opened this issue Jul 1, 2019 · 1 comment
Open

How to Get Transaction Record Receiver #220

Cecil-cc opened this issue Jul 1, 2019 · 1 comment

Comments

@Cecil-cc
Copy link

Cecil-cc commented Jul 1, 2019

Transaction Bean No recipient

How to Get Recipient According to TXHASH

@NashMiao
Copy link
Contributor

NashMiao commented Jul 1, 2019

Currently, we can think user have two kinds of asset - native asset and NEO vm contract asset.

Native Asset

Ontology uses a dual token (ONT and ONG) model. ONT is the coin and can be used for staking in consensus, whereas ONG is the utility token used for on-chain services.

Since the Ontology MainNet went live on June 30th, 2018, MainNet ONT has started to release ONG periodically.

Both ONT and ONG are based on native vm contract, you can find the code in here and here.

So, If you want to get the token's receiver, you need to do by following step:

  1. Get the transaction in blockchain by TxHash .
String txHash = "f3c0f8bfb11531f534ac832b20865c60ea6eb41d7371c38b9a1e006871c56087";
String txJson = (String) ontSdk.getConnect().getTransactionJson(txHash);
  1. Get the Payload in transaction.
JSONObject tx = JSON.parseObject(txJson);
System.out.println(tx.getString("Payload"));
  1. Decode the invoke code in payload by hand.
payload: 00c66b6a14675e90df552510f7485cbb947472bbfb1ccef3d6c86a143a5f33fe68147164f2fbc523d18c5a065956fed0c86a55c86c51c1087472616e736665721400000000000000000000000000000000000000010068164f6e746f6c6f67792e4e61746976652e496e766f6b65
$ python
>>> from ontology.utils.contract_data import ContractDataParser
>>> ContractDataParser.to_int('14')
20
>>> ContractDataParser.to_b58_address('46b1a18af6b7c9f8a4602f9f73eeb3030f0c29b7')
'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
>>> ContractDataParser.to_int('14')
20
>>> ContractDataParser.to_b58_address('feec06b79ed299ea06fcb94abac41aaf3ead7658')
'Af1n2cZHhMZumNqKgw9sfCNoTWu9de4NDn'
>>> ContractDataParser.to_int('08')
8
>>> ContractDataParser.to_utf8_str('7472616e73666572')
'transfer'
>>> ContractDataParser.op_code_to_int('51')
1
>>> ContractDataParser.to_int('16')
22
>>> ContractDataParser.to_utf8_str('4f6e746f6c6f67792e4e61746976652e496e766f6b65')
'Ontology.Native.Invoke'
>>> len('Ontology.Native.Invoke')
22

For more information, you can visit here.

Neo Vm Contract Asset

All the Neo Vm contract assets are based on smart contract. If you want to get the token's receiver, you need to do by following step:

  1. Get the transaction in blockchain by TxHash .
String txHash = "f3c0f8bfb11531f534ac832b20865c60ea6eb41d7371c38b9a1e006871c56087";
String txJson = (String) ontSdk.getConnect().getTransactionJson(txHash);
  1. Get the Payload in transaction.
JSONObject tx = JSON.parseObject(txJson);
System.out.println(tx.getString("Payload"));
  1. Decode the invoke code in payload by hand.

OEP-4, OEP-5 and OEP5 are more easier to decode, you can read the code structure in here.

$ python
>>> from ontology.utils.contract_data import ContractDataParser
>>> ContractDataParser.op_code_to_int('5a')
10
>>> ContractDataParser.to_int('14')
20
>>> ContractDataParser.to_b58_address('feec06b79ed299ea06fcb94abac41aaf3ead7658')
'Af1n2cZHhMZumNqKgw9sfCNoTWu9de4NDn'
>>> ContractDataParser.to_b58_address('46b1a18af6b7c9f8a4602f9f73eeb3030f0c29b7')
'ANDfjwrUroaVtvBguDtrWKRMyxFwvVwnZD'
>>> ContractDataParser.op_code_to_int('53')
3
>>> ContractDataParser.to_int('08')
8
>>> ContractDataParser.to_reserve_hex_str('e94e5c8c35a9979e41ff712b9e9d3e7482b6db1d')
'1ddbb682743e9d9e2b71ff419e97a9358c5c4ee9'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants