【确认以太坊转账hash是否成功的唯一依据】Receipts收据中的status字段的判断且token转账的event log字段进行分析,才能正确的判断一笔token转账是否真实成功

以太坊最新漏洞首发!重大发现!以太坊Token转账有效性标识字段的含义调整或将引发新一轮对交易站的攻击!

参考:https://www.douban.com/group/topic/125523381/

 

hash失败案例参考https://blog.csdn.net/weixin_43343144/article/details/101052060

 

国外以太坊参考:https://ethereum.stackexchange.com/questions/28077/how-do-i-detect-a-failed-transaction-after-the-byzantium-fork-as-the-revert-opco

 

// 等待hash交易完成最终写入区块返回收据【唯一确保交易100%完成的凭据】
    waitForTransactionFinish (transactionHash, successFunc = null, failFunc = null) {
        return Utils.tryCatchGlobalPromise(async (resolve, reject) => {
            // ethers.js库官方说明:waitForTransaction等价于provider.once(transactionHash,callbackFunc)仅一次监听!
            // 【非常重要】这里不能使用await调用【必须异步执行,同步的话会出现无限期等待的情况】
            return this.active_wallet.provider.waitForTransaction(transactionHash).then((transactionReceipt) => {
                // 以太坊交易成功的唯一判断依据:status为1,牵涉到转账的话logs数组一定是有event事件日志数据
                console.log("监听当前hash挖掘的收据交易状态【为1代表交易成功、为0代表交易失败】transactionReceipt.status:", transactionReceipt.status);
                console.log("监听当前hash挖掘的收据交易event事件日志transactionReceipt.logs:", transactionReceipt.logs);
                if (transactionReceipt.status === 1 && transactionReceipt.logs.length !== 0) {
                    Utils.isFunction(successFunc) ? successFunc(transactionReceipt) : null;
                    return resolve(transactionReceipt);
                }
                Utils.isFunction(failFunc) ? failFunc() : null;
                return resolve(null);
            }).catch((error) => {
                console.log(`监听的当前hash:${transactionHash}失败,错误error:${error}`);
                console.log("注意:本次hash挖掘失败,不会更新任何数据,下一轮会再次监听此hash,知道hash交易成功得到收据凭证transactionReceipt");
                return resolve(null);
            });
        });
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值