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

dry_run的时候,显示token的变化量和余额 #55

Closed
wk3368 opened this issue Mar 21, 2022 · 7 comments
Closed

dry_run的时候,显示token的变化量和余额 #55

wk3368 opened this issue Mar 21, 2022 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@wk3368
Copy link
Contributor

wk3368 commented Mar 21, 2022

提醒用户,防止恶意的合约造成用户损失。

@jolestar jolestar added enhancement New feature or request help wanted Extra attention is needed labels May 3, 2022
@wk3368
Copy link
Contributor Author

wk3368 commented Jun 20, 2022

一个转账的交易:

curl --location --request POST 'https://barnard-seed.starcoin.org'
--header 'Content-Type: application/json'
--data-raw '{
"id":200,
"jsonrpc":"2.0",
"method":"contract.dry_run",
"params":[
{
"chain_id": 251,
"gas_unit_price": 1,
"sender": "0x3f19d5422824f47e6c021978cee98f35",
"sender_public_key": "0xc51dada886afe59d4651f36b56f3c4a1a84da53dfbddf396d81a5b36ab5cdc26",
"sequence_number": 325,
"max_gas_amount": 10000000,
"script": {
"code": "0x1::TransferScripts::peer_to_peer_v2",
"type_args": ["0x1::STC::STC"],
"args": ["0xd42cce7f1afe838b9f40a6583da07693", "10000000u128"]
}
}
]
}'

这是dry_run的rensponse:

{
    "jsonrpc": "2.0",
    "result": {
        "events": [
            {
                "data": "0x000000000000000000000000000000010353544303535443",
                "event_key": "0x0200000000000000d42cce7f1afe838b9f40a6583da07693",
                "event_seq_number": "0",
                "type_tag": "0x00000000000000000000000000000001::Account::AcceptTokenEvent"
            },
            {
                "data": "0x8096980000000000000000000000000000000000000000000000000000000001035354430353544300",
                "event_key": "0x00000000000000003f19d5422824f47e6c021978cee98f35",
                "event_seq_number": "211",
                "type_tag": "0x00000000000000000000000000000001::Account::WithdrawEvent"
            },
            {
                "data": "0x8096980000000000000000000000000000000000000000000000000000000001035354430353544300",
                "event_key": "0x0100000000000000d42cce7f1afe838b9f40a6583da07693",
                "event_seq_number": "0",
                "type_tag": "0x00000000000000000000000000000001::Account::DepositEvent"
            }
        ],
        "explained_status": "Executed",
        "gas_used": "284531",
        "status": "Executed",
        "write_set": [
            {
                "access_path": "0x00000000000000000000000000000001/1/0x00000000000000000000000000000001::TransactionFee::TransactionFee<0x00000000000000000000000000000001::STC::STC>",
                "action": "Value",
                "value": {
                    "Resource": {
                        "json": {
                            "fee": {
                                "value": 284531
                            }
                        },
                        "raw": "0x73570400000000000000000000000000"
                    }
                }
            },
            {
                "access_path": "0x3f19d5422824f47e6c021978cee98f35/1/0x00000000000000000000000000000001::Account::Account",
                "action": "Value",
                "value": {
                    "Resource": {
                        "json": {
                            "accept_token_events": {
                                "counter": 9,
                                "guid": "0x02000000000000003f19d5422824f47e6c021978cee98f35"
                            },
                            "authentication_key": "0xc804cb6c5652488f61386a0107bc88cd3f19d5422824f47e6c021978cee98f35",
                            "deposit_events": {
                                "counter": 932,
                                "guid": "0x01000000000000003f19d5422824f47e6c021978cee98f35"
                            },
                            "key_rotation_capability": {
                                "vec": [
                                    {
                                        "account_address": "0x3f19d5422824f47e6c021978cee98f35"
                                    }
                                ]
                            },
                            "sequence_number": 326,
                            "withdraw_events": {
                                "counter": 212,
                                "guid": "0x00000000000000003f19d5422824f47e6c021978cee98f35"
                            },
                            "withdrawal_capability": {
                                "vec": [
                                    {
                                        "account_address": "0x3f19d5422824f47e6c021978cee98f35"
                                    }
                                ]
                            }
                        },
                        "raw": "0x20c804cb6c5652488f61386a0107bc88cd3f19d5422824f47e6c021978cee98f35013f19d5422824f47e6c021978cee98f35013f19d5422824f47e6c021978cee98f35d4000000000000001800000000000000003f19d5422824f47e6c021978cee98f35a4030000000000001801000000000000003f19d5422824f47e6c021978cee98f3509000000000000001802000000000000003f19d5422824f47e6c021978cee98f354601000000000000"
                    }
                }
            },
            {
                "access_path": "0x3f19d5422824f47e6c021978cee98f35/1/0x00000000000000000000000000000001::Account::Balance<0x00000000000000000000000000000001::STC::STC>",
                "action": "Value",
                "value": {
                    "Resource": {
                        "json": {
                            "token": {
                                "value": 1367306027555
                            }
                        },
                        "raw": "0x2342ca593e0100000000000000000000"
                    }
                }
            },
            {
                "access_path": "0xd42cce7f1afe838b9f40a6583da07693/1/0x00000000000000000000000000000001::Account::Account",
                "action": "Value",
                "value": {
                    "Resource": {
                        "json": {
                            "accept_token_events": {
                                "counter": 1,
                                "guid": "0x0200000000000000d42cce7f1afe838b9f40a6583da07693"
                            },
                            "authentication_key": "0x0000000000000000000000000000000000000000000000000000000000000000",
                            "deposit_events": {
                                "counter": 1,
                                "guid": "0x0100000000000000d42cce7f1afe838b9f40a6583da07693"
                            },
                            "key_rotation_capability": {
                                "vec": [
                                    {
                                        "account_address": "0xd42cce7f1afe838b9f40a6583da07693"
                                    }
                                ]
                            },
                            "sequence_number": 0,
                            "withdraw_events": {
                                "counter": 0,
                                "guid": "0x0000000000000000d42cce7f1afe838b9f40a6583da07693"
                            },
                            "withdrawal_capability": {
                                "vec": [
                                    {
                                        "account_address": "0xd42cce7f1afe838b9f40a6583da07693"
                                    }
                                ]
                            }
                        },
                        "raw": "0x20000000000000000000000000000000000000000000000000000000000000000001d42cce7f1afe838b9f40a6583da0769301d42cce7f1afe838b9f40a6583da076930000000000000000180000000000000000d42cce7f1afe838b9f40a6583da076930100000000000000180100000000000000d42cce7f1afe838b9f40a6583da076930100000000000000180200000000000000d42cce7f1afe838b9f40a6583da076930000000000000000"
                    }
                }
            },
            {
                "access_path": "0xd42cce7f1afe838b9f40a6583da07693/1/0x00000000000000000000000000000001::Account::AutoAcceptToken",
                "action": "Value",
                "value": {
                    "Resource": {
                        "json": {
                            "enable": true
                        },
                        "raw": "0x01"
                    }
                }
            },
            {
                "access_path": "0xd42cce7f1afe838b9f40a6583da07693/1/0x00000000000000000000000000000001::Account::Balance<0x00000000000000000000000000000001::STC::STC>",
                "action": "Value",
                "value": {
                    "Resource": {
                        "json": {
                            "token": {
                                "value": 10000000
                            }
                        },
                        "raw": "0x80969800000000000000000000000000"
                    }
                }
            },
            {
                "access_path": "0xd42cce7f1afe838b9f40a6583da07693/1/0x00000000000000000000000000000001::Event::EventHandleGenerator",
                "action": "Value",
                "value": {
                    "Resource": {
                        "json": {
                            "addr": "0xd42cce7f1afe838b9f40a6583da07693",
                            "counter": 3
                        },
                        "raw": "0x0300000000000000d42cce7f1afe838b9f40a6583da07693"
                    }
                }
            }
        ]
    },
    "id": 200
}
  1. 把events数组里面的每一条记录给解析出来?
  2. dry_run和 dry_run_raw的response是一样的,对不?

@jolestar
Copy link
Member

主要是通过 access_path 来判断,比如:

     {
                "access_path": "0xd42cce7f1afe838b9f40a6583da07693/1/0x00000000000000000000000000000001::Account::Balance<0x00000000000000000000000000000001::STC::STC>",
                "action": "Value",
                "value": {
                    "Resource": {
                        "json": {
                            "token": {
                                "value": 10000000
                            }
                        },
                        "raw": "0x80969800000000000000000000000000"
                    }
                }
            },

这个就是用户 stc 余额的变化。相当于通过 dry run 的 output 和用户当前的状态进行比较,发现 diff。感觉这个可以提供成 js sdk 的方法,别的地方应该也可以用到。

@jolestar
Copy link
Member

感觉 Event 也可以利用一下,但没想好怎么用。

@wk3368
Copy link
Contributor Author

wk3368 commented Jun 20, 2022

"access_path": "0xd42cce7f1afe838b9f40a6583da07693/1/0x00000000000000000000000000000001::Account::Balance<0x00000000000000000000000000000001::STC::STC>",

这个access_path的路径有规律吗?

/1/0x00000000000000000000000000000001::Account::Balance 是这样的规律吗?

@jolestar
Copy link
Member

address/1代表resource/StructTag value 是 resource bcs 二进制
address/0代表code/ModuleName value 是 module bytecode

@wk3368
Copy link
Contributor Author

wk3368 commented Jun 28, 2022

2022-06-28 17 29 16

swap的交易确认页面,效果如图,包括了token的图标,名字,余额前后的值和变化量,鼠标滑过token图标,会显示tokenCode的全称。

@wk3368
Copy link
Contributor Author

wk3368 commented Jun 30, 2022

Supported in V4.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants