function getRawTransaction(tx) {
function addKey(accum, key) {
if (tx[key]) { accum[key] = tx[key]; }
return accum;
}
// 提取交易和签名的相关部分
const txFields = "accessList chainId data gasPrice gasLimit maxFeePerGas maxPriorityFeePerGas nonce to type value".split(" ");
const sigFields = "v r s".split(" ");
// 对已签名的交易进行验证
const raw = utils.serializeTransaction(txFields.reduce(addKey, { }), sigFields.reduce(addKey, { }));
// 再次检查一切是否正确能够顺利运行
if (utils.keccak256(raw) !== tx.hash) { throw new Error("serializing failed!"); }
return raw;
}
The content of this site is licensed under the Creative Commons License. Generated on January 11, 2023, 9:24pm.