馬蹄鏈polygon智慧合約dapp代幣流動性挖礦分紅系統開發詳情及方案

xiaofufu發表於2023-03-11

  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]:


  """開發合約I59詳細2OO7系統3O69


  事件日誌的解碼和整理


  :param tx_receipt_event_log:


  :return:


  """


  log_details:List[ORDER_TX_RES_DETAILS_LIKE]=[]


  if isinstance(tx_receipt_event_log,Tuple):開發流程:yy625019


  #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"]["value"],decimals=self.coin_decimals_dict[coin_name]))


  from_addr:str=d["args"]["from"]


  to_addr:str=d["args"]["to"]


  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_addr}:{coin_name}減少{transfer_vol}")


  else:


  print(f"未知地址{from_addr}:{coin_name}減少{transfer_vol}")


  if to_addr in self.account_addr_list:#如果是賬號的地址


  print(f"是賬號的地址{to_addr}:{coin_name}增加{transfer_vol}")


  order_res:ORDER_TX_RES_DETAILS_LIKE={"coin_name":coin_name,"side":"buy","vol":transfer_vol,"account_addr":to_addr}


  log_details.append(order_res)


  elif to_addr in self.pair_name_to_addr_dict.values():#如果是pair合約的地址


  print(f"是pair合約的地址{to_addr}:{coin_name}增加{transfer_vol}")


  else:


  print(f"未知地址{to_addr}:{coin_name}增加{transfer_vol}")


  return log_details


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69956839/viewspace-2939178/,如需轉載,請註明出處,否則將追究法律責任。

相關文章