UNPKG

@hashgraph/sdk

Version:
3 lines (2 loc) 8.31 kB
import t from"./ContractLogInfo.js";import e from"./ContractId.js";import n from"../account/AccountId.js";import s from"bignumber.js";import{encode as r}from"../encoding/hex.js";import{decode as o}from"../encoding/utf8.js";import{safeView as i}from"../util.js";import{defaultAbiCoder as u}from"@ethersproject/abi";import g from"long";import a from"./ContractNonceInfo.js";class l{constructor(t){this._createResult=t._createResult,this.contractId=t.contractId,this.bytes=t.bytes,this.errorMessage=t.errorMessage,this.bloom=t.bloom,this.gasUsed=t.gasUsed,this.logs=t.logs,this.createdContractIds=t.createdContractIds,this.evmAddress=t.evmAddress,this.stateChanges=t.stateChanges,this.gas=t.gas,this.amount=t.amount,this.functionParameters=t.functionParameters,this.senderAccountId=t.senderAccountId,this.contractNonces=t.contractNonces,this.signerNonce=t.signerNonce}static _fromProtobuf(s,r){const o=s.contractID,i=s.gasUsed,u=s.gas?s.gas:-1,c=s.amount?s.amount:-1;return new l({_createResult:r,bytes:s.contractCallResult,contractId:null!=o?e._fromProtobuf(o):null,errorMessage:null!=s.errorMessage?s.errorMessage:null,bloom:s.bloom,gasUsed:i instanceof g?i:g.fromValue(i),logs:(null!=s.logInfo?s.logInfo:[]).map(e=>t._fromProtobuf(e)),createdContractIds:(null!=s.createdContractIDs?s.createdContractIDs:[]).map(t=>e._fromProtobuf(t)),evmAddress:null!=s.evmAddress&&Object.hasOwn(s.evmAddress,"value")&&null!=s.evmAddress.value?s.evmAddress.value:null,stateChanges:[],gas:u instanceof g?u:g.fromValue(u),amount:c instanceof g?c:g.fromValue(c),functionParameters:s.functionParameters,senderAccountId:null!=s.senderId?n._fromProtobuf(s.senderId):null,contractNonces:(null!=s.contractNonces?s.contractNonces:[]).map(t=>a._fromProtobuf(t)),signerNonce:null!=s.signerNonce&&Object.hasOwn(s.signerNonce,"value")&&s.signerNonce.value||null})}asBytes(){return this.bytes}getString(t){return o(this.getBytes(t))}getBytes(t){const e=this.getInt32(t),n=i(this.bytes).getInt32(e+28);return this.bytes.subarray(e+32,e+32+n)}getBytes32(t){return this.bytes.subarray(32*(null!=t?t:0),32*(null!=t?t:0)+32)}getBool(t){return 0!==this.bytes[32*(null!=t?t:0)+31]}getInt8(t){const e=32*(null!=t?t:0)+31;return i(this.bytes).getInt8(e)}getUint8(t){return this.bytes[32*(null!=t?t:0)+31]}getInt16(t){const e=32*(null!=t?t:0)+28;return i(this.bytes).getInt32(e)}getUint16(t){const e=32*(null!=t?t:0)+28;return i(this.bytes).getUint32(e)}getInt24(t){const e=32*(null!=t?t:0)+28;return i(this.bytes).getInt32(e)}getUint24(t){const e=32*(null!=t?t:0)+28;return i(this.bytes).getUint32(e)}getInt32(t){const e=32*(null!=t?t:0)+28;return i(this.bytes).getInt32(e)}getUint32(t){const e=32*(null!=t?t:0)+28;return i(this.bytes).getUint32(e)}getInt40(t){const e=u.decode(["int40"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint40(t){return new s(r(this._getBytes32(t).subarray(27,32)),16)}getInt48(t){const e=u.decode(["int48"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint48(t){return new s(r(this._getBytes32(t).subarray(26,32)),16)}getInt56(t){const e=u.decode(["int56"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint56(t){return new s(r(this._getBytes32(t).subarray(25,32)),16)}getInt64(t){const e=u.decode(["int64"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint64(t){return new s(r(this._getBytes32(t).subarray(24,32)),16)}getInt72(t){const e=u.decode(["int72"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint72(t){return new s(r(this._getBytes32(t).subarray(23,32)),16)}getInt80(t){const e=u.decode(["int80"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint80(t){return new s(r(this._getBytes32(t).subarray(22,32)),16)}getInt88(t){const e=u.decode(["int88"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint88(t){return new s(r(this._getBytes32(t).subarray(21,32)),16)}getInt96(t){const e=u.decode(["int96"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint96(t){return new s(r(this._getBytes32(t).subarray(20,32)),16)}getInt104(t){const e=u.decode(["int104"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint104(t){return new s(r(this._getBytes32(t).subarray(19,32)),16)}getInt112(t){const e=u.decode(["int112"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint112(t){return new s(r(this._getBytes32(t).subarray(18,32)),16)}getInt120(t){const e=u.decode(["int120"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint120(t){return new s(r(this._getBytes32(t).subarray(17,32)),16)}getInt128(t){const e=u.decode(["int128"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint128(t){return new s(r(this._getBytes32(t).subarray(16,32)),16)}getInt136(t){const e=u.decode(["int136"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint136(t){return new s(r(this._getBytes32(t).subarray(15,32)),16)}getInt144(t){const e=u.decode(["int144"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint144(t){return new s(r(this._getBytes32(t).subarray(14,32)),16)}getInt152(t){const e=u.decode(["int152"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint152(t){return new s(r(this._getBytes32(t).subarray(13,32)),16)}getInt160(t){const e=u.decode(["int160"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint160(t){return new s(r(this._getBytes32(t).subarray(12,32)),16)}getInt168(t){const e=u.decode(["int168"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint168(t){return new s(r(this._getBytes32(t).subarray(11,32)),16)}getInt176(t){const e=u.decode(["int176"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint176(t){return new s(r(this._getBytes32(t).subarray(10,32)),16)}getInt184(t){const e=u.decode(["int184"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint184(t){return new s(r(this._getBytes32(t).subarray(9,32)),16)}getInt192(t){const e=u.decode(["int192"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint192(t){return new s(r(this._getBytes32(t).subarray(8,32)),16)}getInt200(t){const e=u.decode(["int200"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint200(t){return new s(r(this._getBytes32(t).subarray(7,32)),16)}getInt208(t){const e=u.decode(["int208"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint208(t){return new s(r(this._getBytes32(t).subarray(6,32)),16)}getInt216(t){const e=u.decode(["int216"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint216(t){return new s(r(this._getBytes32(t).subarray(5,32)),16)}getInt224(t){const e=u.decode(["int224"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint224(t){return new s(r(this._getBytes32(t).subarray(4,32)),16)}getInt232(t){const e=u.decode(["int232"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint232(t){return new s(r(this._getBytes32(t).subarray(3,32)),16)}getInt240(t){const e=u.decode(["int240"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint240(t){return new s(r(this._getBytes32(t).subarray(2,32)),16)}getInt248(t){const e=u.decode(["int248"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint248(t){return new s(r(this._getBytes32(t).subarray(1,32)),16)}getInt256(t){const e=u.decode(["int256"],this._getBytes32(null!=t?t:0));return new s(e.toString())}getUint256(t){return new s(r(this._getBytes32(t)),16)}getAddress(t){return r(this.bytes.subarray(32*(null!=t?t:0)+12,32*(null!=t?t:0)+32))}getResult(t){return u.decode(t,this.bytes)}_getBytes32(t){return this.bytes.subarray(32*(null!=t?t:0),32*(null!=t?t:0)+32)}_toProtobuf(){return{contractID:null!=this.contractId?this.contractId._toProtobuf():null,contractCallResult:this.bytes,errorMessage:this.errorMessage,bloom:this.bloom,gasUsed:this.gasUsed,logInfo:this.logs.map(t=>t._toProtobuf()),createdContractIDs:this.createdContractIds.map(t=>t._toProtobuf()),evmAddress:null!=this.evmAddress?{value:this.evmAddress}:null,gas:this.gas,amount:this.amount,functionParameters:this.functionParameters,senderId:null!=this.senderAccountId?this.senderAccountId._toProtobuf():null,contractNonces:this.contractNonces.map(t=>t._toProtobuf()),signerNonce:null!=this.signerNonce?{value:this.signerNonce}:null}}}export{l as default}; //# sourceMappingURL=ContractFunctionResult.js.map