UNPKG

@hiero-ledger/sdk

Version:
3 lines (2 loc) 7.44 kB
import t from"./TransactionReceipt.js";import s from"./TransactionId.js";import e from"../Timestamp.js";import n from"../Hbar.js";import o from"../Transfer.js";import r from"../contract/ContractFunctionResult.js";import a from"../account/TokenTransferMap.js";import i from"../account/TokenNftTransferMap.js";import*as u from"@hashgraph/proto";import l from"../schedule/ScheduleId.js";import c from"../token/AssessedCustomFee.js";import m from"../token/TokenAssociation.js";import h from"../Key.js";import f from"../PublicKey.js";import d from"../token/TokenTransfer.js";import p from"../EvmAddress.js";import{encode as T}from"../encoding/hex.js";import k from"../token/PendingAirdropRecord.js";class b{constructor(t){this.receipt=t.receipt,this.transactionHash=t.transactionHash,this.consensusTimestamp=t.consensusTimestamp,this.transactionId=t.transactionId,this.transactionMemo=t.transactionMemo,this.transactionFee=t.transactionFee,this.transfers=t.transfers,this.contractFunctionResult=null!=t.contractFunctionResult?t.contractFunctionResult:null,this.tokenTransfers=t.tokenTransfers,this.tokenTransfersList=t.tokenTransfersList,this.scheduleRef=t.scheduleRef,this.assessedCustomFees=t.assessedCustomFees,this.nftTransfers=t.nftTransfers,this.automaticTokenAssociations=t.automaticTokenAssociations,this.parentConsensusTimestamp=t.parentConsensusTimestamp,this.aliasKey=t.aliasKey,this.duplicates=t.duplicates,this.children=t.children,this.hbarAllowanceAdjustments=t.hbarAllowanceAdjustments,this.tokenAllowanceAdjustments=t.tokenAllowanceAdjustments,this.nftAllowanceAdjustments=t.nftAllowanceAdjustments,this.ethereumHash=t.ethereumHash,this.paidStakingRewards=t.paidStakingRewards,this.prngBytes=t.prngBytes,this.prngNumber=t.prngNumber,this.evmAddress=t.evmAddress,this.newPendingAirdrops=t.newPendingAirdrops,Object.freeze(this)}_toProtobuf(){const t=this.tokenTransfers._toProtobuf(),s=this.nftTransfers._toProtobuf(),e=[];for(const n of t)for(const t of s)null!=n.token&&null!=t.token&&n.token.shardNum===t.token.shardNum&&n.token.realmNum===t.token.realmNum&&n.token.tokenNum===t.token.tokenNum?e.push({token:n.token,transfers:n.transfers,nftTransfers:n.nftTransfers}):(e.push(n),e.push(t));return{duplicateTransactionRecords:this.duplicates.map(t=>t._toProtobuf().transactionRecord),childTransactionRecords:this.children.map(t=>t._toProtobuf().transactionRecord),transactionRecord:{receipt:this.receipt._toProtobuf().receipt,transactionHash:null!=this.transactionHash?this.transactionHash:null,consensusTimestamp:null!=this.consensusTimestamp?this.consensusTimestamp._toProtobuf():null,transactionID:null!=this.transactionId?this.transactionId._toProtobuf():null,memo:null!=this.transactionMemo?this.transactionMemo:null,transactionFee:null!=this.transactionFee?this.transactionFee.toTinybars():null,contractCallResult:null==this.contractFunctionResult||this.contractFunctionResult._createResult?null:this.contractFunctionResult._toProtobuf(),contractCreateResult:null!=this.contractFunctionResult&&this.contractFunctionResult._createResult?this.contractFunctionResult._toProtobuf():null,transferList:null!=this.transfers?{accountAmounts:this.transfers.map(t=>t._toProtobuf())}:null,tokenTransferLists:e,scheduleRef:null!=this.scheduleRef?this.scheduleRef._toProtobuf():null,assessedCustomFees:this.assessedCustomFees.map(t=>t._toProtobuf()),automaticTokenAssociations:this.automaticTokenAssociations.map(t=>t._toProtobuf()),parentConsensusTimestamp:null!=this.parentConsensusTimestamp?this.parentConsensusTimestamp._toProtobuf():null,alias:null!=this.aliasKey?u.proto.Key.encode(this.aliasKey._toProtobufKey()).finish():null,ethereumHash:this.ethereumHash,paidStakingRewards:this.paidStakingRewards.map(t=>t._toProtobuf()),prngBytes:this.prngBytes,prngNumber:null!=this.prngNumber?this.prngNumber:null,evmAddress:null!=this.evmAddress?this.evmAddress.toBytes():null,newPendingAirdrops:this.newPendingAirdrops.map(t=>t.toBytes())}}}static _fromProtobuf(T){const R=T.transactionRecord;let A=null!=R.alias&&R.alias.length>0?h._fromProtobufKey(u.proto.Key.decode(R.alias)):null;A instanceof f||(A=null);const g=null!=T.childTransactionRecords?T.childTransactionRecords.map(t=>b._fromProtobuf({transactionRecord:t})):[],P=null!=T.duplicateTransactionRecords?T.duplicateTransactionRecords.map(t=>b._fromProtobuf({transactionRecord:t})):[],_=null!=R.contractCallResult?r._fromProtobuf(R.contractCallResult,!1):null!=R.contractCreateResult?r._fromProtobuf(R.contractCreateResult,!0):void 0,y=null!=R.newPendingAirdrops?R.newPendingAirdrops.map(t=>k.fromBytes(t)):[];return new b({receipt:t._fromProtobuf({receipt:R.receipt}),transactionHash:null!=R.transactionHash?R.transactionHash:new Uint8Array,consensusTimestamp:e._fromProtobuf(R.consensusTimestamp),transactionId:s._fromProtobuf(R.transactionID),transactionMemo:null!=R.memo?R.memo:"",transactionFee:n.fromTinybars(null!=R.transactionFee?R.transactionFee:0),transfers:o._fromProtobuf(null!=R.transferList&&null!=R.transferList.accountAmounts?R.transferList.accountAmounts:[]),contractFunctionResult:_,tokenTransfers:a._fromProtobuf(null!=R.tokenTransferLists?R.tokenTransferLists:[]),tokenTransfersList:d._fromProtobuf(null!=R.tokenTransferLists?R.tokenTransferLists:[]),scheduleRef:null!=R.scheduleRef?l._fromProtobuf(R.scheduleRef):null,assessedCustomFees:null!=R.assessedCustomFees?R.assessedCustomFees.map(t=>c._fromProtobuf(t)):[],nftTransfers:i._fromProtobuf(null!=R.tokenTransferLists?R.tokenTransferLists:[]),automaticTokenAssociations:null!=R.automaticTokenAssociations?R.automaticTokenAssociations.map(t=>m._fromProtobuf(t)):[],parentConsensusTimestamp:null!=R.parentConsensusTimestamp?e._fromProtobuf(R.parentConsensusTimestamp):null,aliasKey:A,duplicates:P,children:g,hbarAllowanceAdjustments:[],tokenAllowanceAdjustments:[],nftAllowanceAdjustments:[],ethereumHash:null!=R.ethereumHash?R.ethereumHash:null,paidStakingRewards:null!=R.paidStakingRewards?o._fromProtobuf(R.paidStakingRewards):[],prngBytes:null!=R.prngBytes?R.prngBytes:null,prngNumber:null!=R.prngNumber?R.prngNumber:null,evmAddress:null!=R.evmAddress?p.fromBytes(R.evmAddress):null,newPendingAirdrops:y})}static fromBytes(t){return b._fromProtobuf(u.proto.TransactionGetRecordResponse.decode(t))}toBytes(){return u.proto.TransactionGetRecordResponse.encode(this._toProtobuf()).finish()}toJSON(){return{receipt:this.receipt.toJSON(),transactionHash:T(this.transactionHash),consensusTimestamp:this.consensusTimestamp.toDate(),transactionId:this.transactionId.toString(),transactionMemo:this.transactionMemo,transactionFee:this.transactionFee.toTinybars().toString(),transfers:this.transfers.map(t=>t.toJSON()),tokenTransfers:this.tokenTransfers,tokenTransfersList:this.tokenTransfersList.map(t=>t.toJSON()),scheduleRef:this.scheduleRef?.toString()||null,assessedCustomFees:this.assessedCustomFees,nftTransfers:this.nftTransfers,automaticTokenAssociations:this.automaticTokenAssociations,parentConsensusTimestamp:this.parentConsensusTimestamp?.toDate()||null,aliasKey:this.aliasKey?.toString()||null,duplicates:this.duplicates,children:this.children,ethereumHash:null!=this.ethereumHash?T(this.ethereumHash):null,paidStakingRewards:this.paidStakingRewards,prngBytes:null!=this.prngBytes?T(this.prngBytes):null,prngNumber:this.prngNumber,evmAddress:this.evmAddress?.toString()||null}}toString(){return JSON.stringify(this.toJSON())}}export{b as default}; //# sourceMappingURL=TransactionRecord.js.map