UNPKG

@hiero-ledger/sdk

Version:
3 lines (2 loc) 6.32 kB
import t from"../Hbar.js";import e from"../account/AccountId.js";import o from"../file/FileId.js";import n from"./ContractFunctionParameters.js";import i,{TRANSACTION_REGISTRY as r,DEFAULT_AUTO_RENEW_PERIOD as s}from"../transaction/Transaction.js";import a from"long";import c from"../Duration.js";import u from"../Key.js";class d extends i{constructor(e={}){super(),this._bytecodeFileId=null,this._bytecode=null,this._adminKey=null,this._gas=null,this._initialBalance=null,this._proxyAccountId=null,this._autoRenewPeriod=new c(s),this._constructorParameters=null,this._contractMemo=null,this._maxAutomaticTokenAssociations=null,this._defaultMaxTransactionFee=new t(20),this._stakedAccountId=null,this._stakedNodeId=null,this._declineStakingReward=!1,this._autoRenewAccountId=null,null!=e.bytecodeFileId&&this.setBytecodeFileId(e.bytecodeFileId),null!=e.bytecode&&this.setBytecode(e.bytecode),null!=e.adminKey&&this.setAdminKey(e.adminKey),null!=e.gas&&this.setGas(e.gas),null!=e.initialBalance&&this.setInitialBalance(e.initialBalance),null!=e.proxyAccountId&&this.setProxyAccountId(e.proxyAccountId),null!=e.autoRenewPeriod&&this.setAutoRenewPeriod(e.autoRenewPeriod),null!=e.constructorParameters&&this.setConstructorParameters(e.constructorParameters),null!=e.contractMemo&&this.setContractMemo(e.contractMemo),null!=e.maxAutomaticTokenAssociations&&this.setMaxAutomaticTokenAssociations(e.maxAutomaticTokenAssociations),null!=e.stakedAccountId&&this.setStakedAccountId(e.stakedAccountId),null!=e.stakedNodeId&&this.setStakedNodeId(e.stakedNodeId),null!=e.declineStakingReward&&this.setDeclineStakingReward(e.declineStakingReward),null!=e.autoRenewAccountId&&this.setAutoRenewAccountId(e.autoRenewAccountId)}static _fromProtobuf(n,r,s,a,c){const l=c[0].contractCreateInstance;return i._fromProtobufTransactions(new d({bytecodeFileId:null!=l.fileID?o._fromProtobuf(l.fileID):void 0,adminKey:null!=l.adminKey?u._fromProtobufKey(l.adminKey):void 0,gas:null!=l.gas?l.gas:void 0,initialBalance:null!=l.initialBalance?t.fromTinybars(l.initialBalance):void 0,proxyAccountId:null!=l.proxyAccountID?e._fromProtobuf(l.proxyAccountID):void 0,autoRenewPeriod:null!=l.autoRenewPeriod&&null!=l.autoRenewPeriod.seconds?l.autoRenewPeriod.seconds:void 0,constructorParameters:null!=l.constructorParameters?l.constructorParameters:void 0,contractMemo:null!=l.memo?l.memo:void 0,maxAutomaticTokenAssociations:null!=l.maxAutomaticTokenAssociations?l.maxAutomaticTokenAssociations:void 0,stakedAccountId:null!=l.stakedAccountId?e._fromProtobuf(l.stakedAccountId):void 0,stakedNodeId:null!=l.stakedNodeId?l.stakedNodeId:void 0,declineStakingReward:1==l.declineReward,autoRenewAccountId:null!=l.autoRenewAccountId?e._fromProtobuf(l.autoRenewAccountId):void 0}),n,r,s,a,c)}get bytecodeFileId(){return this._bytecodeFileId}setBytecodeFileId(t){return this._requireNotFrozen(),this._bytecodeFileId="string"==typeof t?o.fromString(t):t.clone(),this._bytecode=null,this}get bytecode(){return this._bytecode}setBytecode(t){return this._requireNotFrozen(),this._bytecode=t,this._bytecodeFileId=null,this}get adminKey(){return this._adminKey}setAdminKey(t){return this._requireNotFrozen(),this._adminKey=t,this}get gas(){return this._gas}setGas(t){if(this._requireNotFrozen(),this._gas=t instanceof a?t:a.fromValue(t),this._gas.lessThan(0))throw new Error("Gas cannot be negative number");return this}get initialBalance(){return this._initialBalance}setInitialBalance(e){return this._requireNotFrozen(),this._initialBalance=e instanceof t?e:new t(e),this}get proxyAccountId(){return this._proxyAccountId}setProxyAccountId(t){return this._requireNotFrozen(),this._proxyAccountId=t instanceof e?t:e.fromString(t),this}get autoRenewPeriod(){return this._autoRenewPeriod}setAutoRenewPeriod(t){return this._requireNotFrozen(),this._autoRenewPeriod=t instanceof c?t:new c(t),this}get constructorParameters(){return this._constructorParameters}setConstructorParameters(t){return this._requireNotFrozen(),this._constructorParameters=t instanceof n?t._build():t,this}get contractMemo(){return this._contractMemo}setContractMemo(t){return this._requireNotFrozen(),this._contractMemo=t,this}get maxAutomaticTokenAssociations(){return this._maxAutomaticTokenAssociations}setMaxAutomaticTokenAssociations(t){return this._maxAutomaticTokenAssociations=t,this}get stakedAccountId(){return this._stakedAccountId}setStakedAccountId(t){return this._requireNotFrozen(),this._stakedAccountId="string"==typeof t?e.fromString(t):t,this._stakedNodeId=null,this}get stakedNodeId(){return this._stakedNodeId}setStakedNodeId(t){return this._requireNotFrozen(),this._stakedNodeId=a.fromValue(t),this._stakedAccountId=null,this}get declineStakingRewards(){return this._declineStakingReward}setDeclineStakingReward(t){return this._requireNotFrozen(),this._declineStakingReward=t,this}get autoRenewAccountId(){return this._autoRenewAccountId}setAutoRenewAccountId(t){return this._requireNotFrozen(),this._autoRenewAccountId="string"==typeof t?e.fromString(t):t,this}_validateChecksums(t){null!=this._bytecodeFileId&&this._bytecodeFileId.validateChecksum(t),null!=this._proxyAccountId&&this._proxyAccountId.validateChecksum(t)}_execute(t,e){return t.smartContract.createContract(e)}_getTransactionDataCase(){return"contractCreateInstance"}_makeTransactionData(){return{fileID:null!=this._bytecodeFileId?this._bytecodeFileId._toProtobuf():null,initcode:this._bytecode,adminKey:null!=this._adminKey?this._adminKey._toProtobufKey():null,gas:this._gas,initialBalance:null!=this._initialBalance?this._initialBalance.toTinybars():null,proxyAccountID:null!=this._proxyAccountId?this._proxyAccountId._toProtobuf():null,autoRenewPeriod:this._autoRenewPeriod._toProtobuf(),constructorParameters:this._constructorParameters,memo:this._contractMemo,maxAutomaticTokenAssociations:this._maxAutomaticTokenAssociations,stakedAccountId:null!=this.stakedAccountId?this.stakedAccountId._toProtobuf():null,stakedNodeId:this.stakedNodeId,declineReward:this.declineStakingRewards,autoRenewAccountId:null!=this._autoRenewAccountId?this._autoRenewAccountId._toProtobuf():null}}_getLogId(){return`ContractCreateTransaction:${this._transactionIds.current.validStart.toString()}`}}r.set("contractCreateInstance",d._fromProtobuf);export{d as default}; //# sourceMappingURL=ContractCreateTransaction.js.map