签名签名buyTokenByTokenWithPermission ETH BSC内存_signature bytes



我目前正在编写一个python脚本与BSC合约交互。

我不知道如何为下面的txhash函数生成bytes_signature。我一定是漏掉了什么简单的东西。

[8]:  3deec388befec448046d583d65e15cd77aa9c74ba8c534305089f5869ffe9208
[9]:  7f29af0ba8d129018f19a520a8b342b0ea90df02aed99a4b28f8db2dc61df072

https://bscscan.com/tx/0x94e9df05600e46ae0ef5fd7dc890a44d514e8dd08283a4e909410fac6220efe5

函数:buyTokenByTokenWithPermission(addres_beneficiary, addres_token, uint256 _amount, addres_candidate, uint256 _maxAmount, uint256 _minAmount, bytes _signature) ***

MethodID: 0xa1491efc
[0]:  0000000000000000000000002cff6fb5a463735d65c29d933ce7f1c45350cb33
[1]:  000000000000000000000000e9e7cea3dedca5984780bafc599bd69add087d56
[2]:  000000000000000000000000000000000000000000000005e74a8505e80a0000
[3]:  0000000000000000000000002cff6fb5a463735d65c29d933ce7f1c45350cb33
[4]:  000000000000000000000000000000000000000000000094f138d51f01ba2f70
[5]:  0000000000000000000000000000000000000000000000000000000000000000
[6]:  00000000000000000000000000000000000000000000000000000000000000e0
[7]:  0000000000000000000000000000000000000000000000000000000000000041
[8]:  3deec388befec448046d583d65e15cd77aa9c74ba8c534305089f5869ffe9208
[9]:  7f29af0ba8d129018f19a520a8b342b0ea90df02aed99a4b28f8db2dc61df072
[10]: 1c00000000000000000000000000000000000000000000000000000000000000

查看下面的更多信息

function buyTokenByTokenWithPermission(
address _beneficiary,
address _token,
uint256 _amount,
address _candidate,
uint256 _maxAmount,
uint256 _minAmount,
bytes memory _signature
) public whenNotPaused nonReentrant {
require(offeredCurrencies[_token].rate != 0, "POOL::PURCHASE_METHOD_NOT_ALLOWED");
require(_validPurchase(), "POOL::ENDED");
require(_verifyWhitelist(_candidate, _maxAmount, _minAmount, _signature), "POOL:INVALID_SIGNATURE");
_preValidatePurchase(_beneficiary, _amount);
uint256 tokens = _getOfferedCurrencyToTokenAmount(_token, _amount);
require(getAvailableTokensForSale() >= tokens, "POOL::NOT_ENOUGHT_TOKENS_FOR_SALE");
require(tokens >= _minAmount || userPurchased[_candidate].add(tokens) >= _minAmount, "POOL::MIN_AMOUNT_UNREACHED");
require(userPurchased[_candidate].add(tokens) <= _maxAmount, "POOL:PURCHASE_AMOUNT_EXCEED_ALLOWANCE");
_forwardTokenFunds(_token, _amount);
_updatePurchasingState(_amount, tokens);
investedAmountOf[_token][_candidate] = investedAmountOf[address(0)][_candidate].add(_amount);
emit TokenPurchaseByToken(
msg.sender,
_beneficiary,
_token,
_amount,
tokens
);
}

calldata解码示例:

const InputDataDecoder = require('ethereum-input-data-decoder')
const abi = [
{
"inputs": [
{
"internalType": "address",
"name": "_beneficiary",
"type": "address"
},
{
"internalType": "address",
"name": "_token",
"type": "address"
},
{
"internalType": "uint256",
"name": "_amount",
"type": "uint256"
},
{
"internalType": "address",
"name": "_candidate",
"type": "address"
},
{
"internalType": "uint256",
"name": "_maxAmount",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_minAmount",
"type": "uint256"
},
{
"internalType": "bytes",
"name": "_signature",
"type": "bytes"
}
],
"name": "buyTokenByTokenWithPermission",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
]
const data = '0xa1491efc0000000000000000000000002cff6fb5a463735d65c29d933ce7f1c45350cb33000000000000000000000000e9e7cea3dedca5984780bafc599bd69add087d56000000000000000000000000000000000000000000000005e74a8505e80a00000000000000000000000000002cff6fb5a463735d65c29d933ce7f1c45350cb33000000000000000000000000000000000000000000000094f138d51f01ba2f70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000413deec388befec448046d583d65e15cd77aa9c74ba8c534305089f5869ffe92087f29af0ba8d129018f19a520a8b342b0ea90df02aed99a4b28f8db2dc61df0721c00000000000000000000000000000000000000000000000000000000000000'
const decoder = new InputDataDecoder(abi)
const decoded = decoder.decodeData(data)
const signature = '0x' + decoded.inputs[6].toString('hex')
console.log(signature) // 0x3deec388befec448046d583d65e15cd77aa9c74ba8c534305089f5869ffe92087f29af0ba8d129018f19a520a8b342b0ea90df02aed99a4b28f8db2dc61df0721c

相关内容

  • 没有找到相关文章

最新更新