Skip to content

Commit

Permalink
Add ESDT transfers to smart contract results
Browse files Browse the repository at this point in the history
  • Loading branch information
jaumealoy committed Apr 12, 2024
1 parent 426cae6 commit 62ab679
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 2 deletions.
4 changes: 4 additions & 0 deletions sdk/core/src/data/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ pub struct ApiSmartContractResult {
pub code_metadata: Option<String>,
pub return_message: Option<String>,
pub original_sender: Option<String>,
#[serde(default)]
pub tokens: Option<Vec<String>>,
#[serde(default, rename = "esdtValues")]
pub esdt_values: Option<Vec<String>>
}

#[derive(Debug, Clone, Serialize, Deserialize)]
Expand Down
137 changes: 135 additions & 2 deletions sdk/core/tests/transaction_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,71 @@ pub fn deserialize_notarized_transaction() {
"hyperblockNonce": 0,
"hyperblockHash": "",
"timestamp": 1681142808,
"smartContractResults": [],
"smartContractResults": [
{
"hash": "648c0dd8fe6e6ddd9d68b41cc6ba3233bed143623c1c5a7839b75dad5427b8a9",
"nonce": 0,
"value": 0,
"receiver": "erd177p2msp2rzhsnc32cq4kxy703yxrfxejfz8a7kzwdqw8ma734d4qtzk80t",
"sender": "erd1qqqqqqqqqqqqqpgqeel2kumf0r8ffyhth7pqdujjat9nx0862jpsg2pqaq",
"data": "ESDTTransfer@5745474c442d626434643739@011b37ba3417e581",
"prevTxHash": "61251d2ef8e89ead331963c7213150f6265c765905c66c6a0ae88c00bda159c3",
"originalTxHash": "61251d2ef8e89ead331963c7213150f6265c765905c66c6a0ae88c00bda159c3",
"gasLimit": 0,
"gasPrice": 1000000000,
"callType": 0,
"originalSender": "erd177p2msp2rzhsnc32cq4kxy703yxrfxejfz8a7kzwdqw8ma734d4qtzk80t",
"logs": {
"address": "erd177p2msp2rzhsnc32cq4kxy703yxrfxejfz8a7kzwdqw8ma734d4qtzk80t",
"events": [
{
"address": "erd1qqqqqqqqqqqqqpgqeel2kumf0r8ffyhth7pqdujjat9nx0862jpsg2pqaq",
"identifier": "ESDTTransfer",
"topics": [
"V0VHTEQtYmQ0ZDc5",
"",
"ARs3ujQX5YE=",
"94KtwCoYrwniKsArYxPPiQw0mzJIj99YTmgcfffRq2o="
],
"data": null,
"additionalData": [
"",
"RVNEVFRyYW5zZmVy",
"V0VHTEQtYmQ0ZDc5",
"ARs3ujQX5YE="
]
},
{
"address": "erd177p2msp2rzhsnc32cq4kxy703yxrfxejfz8a7kzwdqw8ma734d4qtzk80t",
"identifier": "writeLog",
"topics": [
"AAAAAAAAAAAFAM5+q3NpeM6Ukuu/ggbyUurLMzz6VIM="
],
"data": "QDZmNmI=",
"additionalData": [
"QDZmNmI="
]
},
{
"address": "erd177p2msp2rzhsnc32cq4kxy703yxrfxejfz8a7kzwdqw8ma734d4qtzk80t",
"identifier": "completedTxEvent",
"topics": [
"YSUdLvjonq0zGWPHITFQ9iZcdlkFxmxqCuiMAL2hWcM="
],
"data": null,
"additionalData": null
}
]
},
"tokens": [
"WEGLD-bd4d79"
],
"esdtValues": [
"79718691286541697"
],
"operation": "ESDTTransfer"
}
],
"logs": {
"address": "erd1qqqqqqqqqqqqqpgqhe8t5jewej70zupmh44jurgn29psua5l2jps3ntjj3",
"events": []
Expand Down Expand Up @@ -174,7 +238,71 @@ pub fn deserialize_a_transaction_with_token_transfers() {
"hyperblockNonce": 0,
"hyperblockHash": "",
"timestamp": 1681142808,
"smartContractResults": [],
"smartContractResults": [
{
"hash": "648c0dd8fe6e6ddd9d68b41cc6ba3233bed143623c1c5a7839b75dad5427b8a9",
"nonce": 0,
"value": 0,
"receiver": "erd177p2msp2rzhsnc32cq4kxy703yxrfxejfz8a7kzwdqw8ma734d4qtzk80t",
"sender": "erd1qqqqqqqqqqqqqpgqeel2kumf0r8ffyhth7pqdujjat9nx0862jpsg2pqaq",
"data": "ESDTTransfer@5745474c442d626434643739@011b37ba3417e581",
"prevTxHash": "61251d2ef8e89ead331963c7213150f6265c765905c66c6a0ae88c00bda159c3",
"originalTxHash": "61251d2ef8e89ead331963c7213150f6265c765905c66c6a0ae88c00bda159c3",
"gasLimit": 0,
"gasPrice": 1000000000,
"callType": 0,
"originalSender": "erd177p2msp2rzhsnc32cq4kxy703yxrfxejfz8a7kzwdqw8ma734d4qtzk80t",
"logs": {
"address": "erd177p2msp2rzhsnc32cq4kxy703yxrfxejfz8a7kzwdqw8ma734d4qtzk80t",
"events": [
{
"address": "erd1qqqqqqqqqqqqqpgqeel2kumf0r8ffyhth7pqdujjat9nx0862jpsg2pqaq",
"identifier": "ESDTTransfer",
"topics": [
"V0VHTEQtYmQ0ZDc5",
"",
"ARs3ujQX5YE=",
"94KtwCoYrwniKsArYxPPiQw0mzJIj99YTmgcfffRq2o="
],
"data": null,
"additionalData": [
"",
"RVNEVFRyYW5zZmVy",
"V0VHTEQtYmQ0ZDc5",
"ARs3ujQX5YE="
]
},
{
"address": "erd177p2msp2rzhsnc32cq4kxy703yxrfxejfz8a7kzwdqw8ma734d4qtzk80t",
"identifier": "writeLog",
"topics": [
"AAAAAAAAAAAFAM5+q3NpeM6Ukuu/ggbyUurLMzz6VIM="
],
"data": "QDZmNmI=",
"additionalData": [
"QDZmNmI="
]
},
{
"address": "erd177p2msp2rzhsnc32cq4kxy703yxrfxejfz8a7kzwdqw8ma734d4qtzk80t",
"identifier": "completedTxEvent",
"topics": [
"YSUdLvjonq0zGWPHITFQ9iZcdlkFxmxqCuiMAL2hWcM="
],
"data": null,
"additionalData": null
}
]
},
"tokens": [
"WEGLD-bd4d79"
],
"esdtValues": [
"79718691286541697"
],
"operation": "ESDTTransfer"
}
],
"logs": {
"address": "erd1qqqqqqqqqqqqqpgqhe8t5jewej70zupmh44jurgn29psua5l2jps3ntjj3",
"events": []
Expand Down Expand Up @@ -220,6 +348,11 @@ pub fn deserialize_a_transaction_with_token_transfers() {
let esdt_values = tx.esdt_values.unwrap();
assert_eq!(esdt_values[0], "4643258");
assert_eq!(esdt_values[1], "123456");

assert!(tx.smart_contract_results.as_ref().unwrap()[0].tokens.is_some());
assert_eq!(tx.smart_contract_results.as_ref().unwrap()[0].tokens.as_ref().unwrap()[0], "WEGLD-bd4d79");
assert_eq!(tx.smart_contract_results.as_ref().unwrap()[0].esdt_values.as_ref().unwrap()[0], "79718691286541697");

}


Expand Down

0 comments on commit 62ab679

Please sign in to comment.