Golang实现solidity的abi.encodePack方法
1、int类型、address、string进行打包:import ( "encoding/hex" "github.com/ethereum/go-ethereum/accounts/abi" ) ... addressTy, _ := abi.NewType("address", "string", []abi.ArgumentMarshaling{}) bytesTy, _ := abi.NewType("bytes", "string", nil) uint256Ty, _ := abi.NewType("uint256", "uint64", []abi.ArgumentMarshaling{}) args := abi.Arguments{ {Type: addressTy}, {Type: bytesTy}, {Type: uint256Ty} } //尤其注意这里,当string转bytes的时候一定要用hex.DecodeString进行16进制转bytes _params2, _ := hex.DecodeString(params2) packed, err...
Golang实现solidity的abi.encodePack方法
1、int类型、address、string进行打包:import ( "encoding/hex" "github.com/ethereum/go-ethereum/accounts/abi" ) ... addressTy, _ := abi.NewType("address", "string", []abi.ArgumentMarshaling{}) bytesTy, _ := abi.NewType("bytes", "string", nil) uint256Ty, _ := abi.NewType("uint256", "uint64", []abi.ArgumentMarshaling{}) args := abi.Arguments{ {Type: addressTy}, {Type: bytesTy}, {Type: uint256Ty} } //尤其注意这里,当string转bytes的时候一定要用hex.DecodeString进行16进制转bytes _params2, _ := hex.DecodeString(params2) packed, err...
argent钱包源码-(四)中继者发起交易流程
argent钱包中的relayerMananger中的excute方法,是发起中继者交易的入口; transactionManager中的mutilCall方法最终验证交易,并且发起交易,此方法支持发起批量交易; 1、调用relayerManager中的excute方法发起交易;function execute( address _wallet, bytes calldata _data, uint256 _nonce, bytes calldata _signatures, uint256 _gasPrice, uint256 _gasLimit, address _refundToken, address _refundAddress ) external returns (bool) { initial gas = 21k + non_zero_bytes * 16 + zero_bytes * 4 // ~= 21k + calldata.length * [1/3 * 16 + 2/3 * 4] uint256 startGas = gasleft() + 21000 ...
argent钱包源码-(四)中继者发起交易流程
argent钱包中的relayerMananger中的excute方法,是发起中继者交易的入口; transactionManager中的mutilCall方法最终验证交易,并且发起交易,此方法支持发起批量交易; 1、调用relayerManager中的excute方法发起交易;function execute( address _wallet, bytes calldata _data, uint256 _nonce, bytes calldata _signatures, uint256 _gasPrice, uint256 _gasLimit, address _refundToken, address _refundAddress ) external returns (bool) { initial gas = 21k + non_zero_bytes * 16 + zero_bytes * 4 // ~= 21k + calldata.length * [1/3 * 16 + 2/3 * 4] uint256 startGas = gasleft() + 21000 ...
argent钱包源码-(三)模块加载机制
argent加载模块涉及到钱包合约、模块合约和工厂合约,具体流程如下: 1、walletFactory中创建钱包的时候,会调用baseWallet的init方法绑定模块合约,init方法中会将模块合约地址写入到authorised中并设置值为true; walletFactory.sol : _wallet.init(_owner, extendedModules); ... baseWallet.sol: function init(address _owner, address[] calldata _modules) external { require(owner == address(0) && modules == 0, "BW: wallet already initialised"); require(_modules.length > 0, "BW: empty modules"); owner = _owner; modules = _modules.length; for (uint256 i = 0; i < _modules...
argent钱包源码-(三)模块加载机制
argent加载模块涉及到钱包合约、模块合约和工厂合约,具体流程如下: 1、walletFactory中创建钱包的时候,会调用baseWallet的init方法绑定模块合约,init方法中会将模块合约地址写入到authorised中并设置值为true; walletFactory.sol : _wallet.init(_owner, extendedModules); ... baseWallet.sol: function init(address _owner, address[] calldata _modules) external { require(owner == address(0) && modules == 0, "BW: wallet already initialised"); require(_modules.length > 0, "BW: empty modules"); owner = _owner; modules = _modules.length; for (uint256 i = 0; i < _modules...
argent钱包源码-(二)创建钱包流程
一、创建钱包的流程: 1、调用walletFactory的createCounterfactualWallet方法创建钱包; 2、通过输入盐进行加工,生成唯一的盐,创建钱包,得到create2钱包地址; 3、进行管理员验签,调用者必须是walletFactory的管理员; 4、然后初始化创建的钱包,设置钱包主人和模块合约; 5、如果设置了回退token(refundToken)和回退地址(refundAddress),那么调用钱包合约的invoke方法将钱包的钱回退(前提是该钱包地址必须提前转入资产) 详细流程图和合约方法梳理如下:create wallet二、提前转入资产 1、由于钱包地址是通过盐+create2创建的,因此钱包地址可以通过相应的规则提前知晓; 2、walletFactory合约已经提供了提前获取合约地址的方法getAddressForCounterfactualWallet ,因此我们通过调用该方法可以提前获取地址,并且创建钱包之前注入相应的资产。
argent钱包源码-(二)创建钱包流程
一、创建钱包的流程: 1、调用walletFactory的createCounterfactualWallet方法创建钱包; 2、通过输入盐进行加工,生成唯一的盐,创建钱包,得到create2钱包地址; 3、进行管理员验签,调用者必须是walletFactory的管理员; 4、然后初始化创建的钱包,设置钱包主人和模块合约; 5、如果设置了回退token(refundToken)和回退地址(refundAddress),那么调用钱包合约的invoke方法将钱包的钱回退(前提是该钱包地址必须提前转入资产) 详细流程图和合约方法梳理如下:create wallet二、提前转入资产 1、由于钱包地址是通过盐+create2创建的,因此钱包地址可以通过相应的规则提前知晓; 2、walletFactory合约已经提供了提前获取合约地址的方法getAddressForCounterfactualWallet ,因此我们通过调用该方法可以提前获取地址,并且创建钱包之前注入相应的资产。
argent钱包源码-(一)架构
argent钱包源码主要分三大部分: 1、钱包合约:分为 proxy代理合约和逻辑合约,钱包合约没有实现任何的逻辑; 2、模块合约:分为baseWallet合约和模块逻辑合约,通过钱包模块加载机制将模块功能绑定到钱包,该部分实现了钱包的所有功能,包括转账、白名单相关的功能; 3、工厂合约:主要是初始化和创建钱包功能; 结构关系图如下:argent钱包的钱包合约部分,本身并没有任何功能,所有的功能均由模块合约提供 接下来,展开说下这三个部分的主要功能: 钱包合约: 1、init方法:初始化钱包,设置钱包的拥有者和模块。/** * @notice Inits the wallet by setting the owner and authorising a list of modules. * @param _owner The owner. * @param _modules The modules to authorise. */ function init(address _owner, address[] calldata _modules) external { requi...
argent钱包源码-(一)架构
argent钱包源码主要分三大部分: 1、钱包合约:分为 proxy代理合约和逻辑合约,钱包合约没有实现任何的逻辑; 2、模块合约:分为baseWallet合约和模块逻辑合约,通过钱包模块加载机制将模块功能绑定到钱包,该部分实现了钱包的所有功能,包括转账、白名单相关的功能; 3、工厂合约:主要是初始化和创建钱包功能; 结构关系图如下:argent钱包的钱包合约部分,本身并没有任何功能,所有的功能均由模块合约提供 接下来,展开说下这三个部分的主要功能: 钱包合约: 1、init方法:初始化钱包,设置钱包的拥有者和模块。/** * @notice Inits the wallet by setting the owner and authorising a list of modules. * @param _owner The owner. * @param _modules The modules to authorise. */ function init(address _owner, address[] calldata _modules) external { requi...