UNPKG

@hiero-ledger/sdk

Version:
3 lines (2 loc) 3.27 kB
import t,{QUERY_REGISTRY as n}from"../query/Query.js";import e from"./ContractId.js";import r from"../account/AccountId.js";import s from"./ContractFunctionParameters.js";import o from"./ContractFunctionResult.js";import a from"long";import*as c from"@hashgraph/proto";import u from"../PrecheckStatusError.js";import i from"../Status.js";class l extends t{constructor(t={}){super(),this._contractId=null,null!=t.contractId&&this.setContractId(t.contractId),this._gas=null,null!=t.gas&&this.setGas(t.gas),this._functionParameters=null,null!=t.functionParameters&&(t.functionParameters instanceof Uint8Array?this.setFunctionParameters(t.functionParameters):this.setFunction(t.functionParameters.name,t.functionParameters.parameters)),this._maxResultSize=null,null!=t.maxResultSize&&this.setMaxResultSize(t.maxResultSize),this._senderAccountId=null,null!=t.senderAccountId&&this.setSenderAccountId(t.senderAccountId)}static _fromProtobuf(t){const n=t.contractCallLocal;return new l({contractId:null!=n.contractID?e._fromProtobuf(n.contractID):void 0,gas:null!=n.gas?n.gas:void 0,functionParameters:null!=n.functionParameters?n.functionParameters:void 0,maxResultSize:null!=n.maxResultSize?n.maxResultSize:void 0})}get contractId(){return this._contractId}setContractId(t){return this._contractId="string"==typeof t?e.fromString(t):t.clone(),this}get gas(){return this._gas}setGas(t){return this._gas=t instanceof a?t:a.fromValue(t),this}get senderAccountId(){return this._senderAccountId}setSenderAccountId(t){return this._senderAccountId="string"==typeof t?r.fromString(t):t,this}get functionParameters(){return this._functionParameters}setFunctionParameters(t){return this._functionParameters=t,this}setFunction(t,n){return this._functionParameters=(null!=n?n:new s)._build(t),this}setMaxResultSize(t){return this._maxResultSize=t instanceof a?t:a.fromValue(t),this}_validateChecksums(t){null!=this._contractId&&this._contractId.validateChecksum(t)}_mapStatusError(t,n,e){const{nodeTransactionPrecheckCode:r}=this._mapResponseHeader(n),s=i._fromCode(null!=r?r:c.proto.ResponseCodeEnum.OK);if(!n.contractCallLocal.functionResult)return new u({nodeId:e,status:s,transactionId:this._getTransactionId(),contractFunctionResult:null});const o=this._mapResponseSync(n);return new u({nodeId:e,status:s,transactionId:this._getTransactionId(),contractFunctionResult:o})}_execute(t,n){return t.smartContract.contractCallLocalMethod(n)}_mapResponseHeader(t){return t.contractCallLocal.header}_mapResponse(t){const n=t.contractCallLocal;return Promise.resolve(o._fromProtobuf(n.functionResult,!1))}_mapResponseSync(t){const n=t.contractCallLocal;return o._fromProtobuf(n.functionResult,!1)}_onMakeRequest(t){return{contractCallLocal:{header:t,contractID:null!=this._contractId?this._contractId._toProtobuf():null,gas:this._gas,maxResultSize:this._maxResultSize,functionParameters:this._functionParameters,senderId:null!=this._senderAccountId?this._senderAccountId._toProtobuf():null}}}_getLogId(){return`ContractCallQuery:${(null!=this._paymentTransactionId&&null!=this._paymentTransactionId.validStart?this._paymentTransactionId.validStart:this._timestamp).toString()}`}}n.set("contractCallLocal",l._fromProtobuf);export{l as default}; //# sourceMappingURL=ContractCallQuery.js.map