Smart contract is a kind of computer program or transaction protocol,which records the information,events and behaviors of transaction terms,aiming at reducing the demand,arbitration and execution costs for trusted intermediaries.On the Chang'an chain,users can write smart contracts in high-level languages(Golang,Rust,solidity,TinyGo,and C++).After compilation,they are stored in the blockchain in the form of binary files,WASM,and EVM bytecodes.Users can trigger the execution of codes in smart contracts by sending transactions.
args:Dictionary-来自事件的参数。
event:String-事件名称。
logIndex:Number-块中日志索引位置的整数。
transactionIndex:Number-创建的交易索引位置日志的整数。
transactionHash:String,32 Bytes-创建此日志的事务的哈希值。
address:String,32 Bytes-此日志的来源地址。
blockHash:String,32 Bytes-此日志所在块的哈希值。当它挂起时为null。
blockNumber:Number-此日志所在的块号。当它挂起时为null
如下,是一个简单的demo,大家应根据自己的业务场景,具体的去解析链上结果:
def _filter_event_transfer(self,tx_receipt_event_log)->List[ORDER_TX_RES_DETAILS_LIKE]:
事件日志的解码和整理
:param tx_receipt_event_log:
:return:
"""
log_details:List[ORDER_TX_RES_DETAILS_LIKE]=[]
if isinstance(tx_receipt_event_log,Tuple):
#assert len(tx_receipt_event_log)==2,"此函数解析交易,理应只得到2笔Transfer记录"
if len(tx_receipt_event_log)!=2:#交易失败的情况:()
self._logger.error("事件日志函数解析交易,理应只得到2笔Transfer记录")
for d in tx_receipt_event_log:
if d.get("event")=="Transfer":
coin_name:str=self.coin_name_to_addr_dict_reverse[d["address"]]
transfer_vol:str=str(self.from_wei(d"args",decimals=self.coin_decimals_dict[coin_name]))
from_addr:str=d"args"
to_addr:str=d"args"
if from_addr in self.account_addr_list:#如果是账号的地址
print(f"是账号的地址{from_addr}:{coin_name}减少{transfer_vol}")
order_res:ORDER_TX_RES_DETAILS_LIKE={"coin_name":coin_name,"side":"sell","vol":transfer_vol,"account_addr":from_addr}
log_details.append(order_res)
elif from_addr in self.pair_name_to_addr_dict.values():#如果是pair合约的地址
print(f"是pair合约的地址{from_