UNPKG

tronewb

Version:

JavaScript SDK that encapsulates the TRON HTTP API

1 lines 417 kB
(()=>{var e={2862:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.TransactionBuilder=void 0;const o=r(5562),n=r(9193),s=r(9055),a=r(8557),i=r(7035),c=r(3331),u=r(705),d=r(5401);t.TransactionBuilder=class{tronWeb;validator;constructor(e){if(!(e&&e instanceof o.TronWeb))throw new Error("Expected instance of TronWeb");this.tronWeb=e,this.validator=new i.Validator}async sendTrx(e,t=0,r=this.tronWeb.defaultAddress.hex,o={}){t=parseInt(t),this.validator.notValid([{name:"recipient",type:"address",value:e},{name:"origin",type:"address",value:r},{names:["recipient","origin"],type:"notEqual",msg:"Cannot transfer TRX to the same account"},{name:"amount",type:"integer",gt:0,value:t}]);const n={to_address:(0,s.toHex)(e),owner_address:(0,s.toHex)(r),amount:t},a=(0,d.getTransactionOptions)(o);return(0,d.createTransaction)(this.tronWeb,u.ContractType.TransferContract,n,o?.permissionId,a)}async sendToken(e,t=0,r,o=this.tronWeb.defaultAddress.hex,n={}){t=parseInt(t),this.validator.notValid([{name:"recipient",type:"address",value:e},{name:"origin",type:"address",value:o},{names:["recipient","origin"],type:"notEqual",msg:"Cannot transfer tokens to the same account"},{name:"amount",type:"integer",gt:0,value:t},{name:"token ID",type:"tokenId",value:r}]);const a={to_address:(0,s.toHex)(e),owner_address:(0,s.toHex)(o),asset_name:(0,d.fromUtf8)(r),amount:t},i=(0,d.getTransactionOptions)(n);return(0,d.createTransaction)(this.tronWeb,u.ContractType.TransferAssetContract,a,n?.permissionId,i)}async purchaseToken(e,t,r=0,o=this.tronWeb.defaultAddress.hex,n={}){this.validator.notValid([{name:"buyer",type:"address",value:o},{name:"issuer",type:"address",value:e},{names:["buyer","issuer"],type:"notEqual",msg:"Cannot purchase tokens from same account"},{name:"amount",type:"integer",gt:0,value:r},{name:"token ID",type:"tokenId",value:t}]);const a={to_address:(0,s.toHex)(e),owner_address:(0,s.toHex)(o),asset_name:(0,d.fromUtf8)(t),amount:parseInt(r)},i=(0,d.getTransactionOptions)(n);return(0,d.createTransaction)(this.tronWeb,u.ContractType.ParticipateAssetIssueContract,a,n?.permissionId,i)}async freezeBalance(e=0,t=3,r="BANDWIDTH",o=this.tronWeb.defaultAddress.hex,n,a={}){this.validator.notValid([{name:"origin",type:"address",value:o},{name:"receiver",type:"address",value:n,optional:!0},{name:"amount",type:"integer",gt:0,value:e},{name:"duration",type:"integer",gte:3,value:t},{name:"resource",type:"resource",value:r,msg:'Invalid resource provided: Expected "BANDWIDTH" or "ENERGY"'}]);const i={owner_address:(0,s.toHex)(o),frozen_balance:parseInt(e),frozen_duration:parseInt(String(t))};"BANDWIDTH"!==r&&(i.resource=r),(0,c.isNotNullOrUndefined)(n)&&(0,s.toHex)(n)!==(0,s.toHex)(o)&&(i.receiver_address=(0,s.toHex)(n));const l=(0,d.getTransactionOptions)(a);return(0,d.createTransaction)(this.tronWeb,u.ContractType.FreezeBalanceContract,i,a?.permissionId,l)}async unfreezeBalance(e="BANDWIDTH",t=this.tronWeb.defaultAddress.hex,r,o={}){this.validator.notValid([{name:"origin",type:"address",value:t},{name:"receiver",type:"address",value:r,optional:!0},{name:"resource",type:"resource",value:e,msg:'Invalid resource provided: Expected "BANDWIDTH" or "ENERGY"'}]);const n={owner_address:(0,s.toHex)(t)};"BANDWIDTH"!==e&&(n.resource=e),(0,c.isNotNullOrUndefined)(r)&&(0,s.toHex)(r)!==(0,s.toHex)(t)&&(n.receiver_address=(0,s.toHex)(r));const a=(0,d.getTransactionOptions)(o);return(0,d.createTransaction)(this.tronWeb,u.ContractType.UnfreezeBalanceContract,n,o?.permissionId,a)}async freezeBalanceV2(e=0,t="BANDWIDTH",r=this.tronWeb.defaultAddress.hex,o={}){this.validator.notValid([{name:"origin",type:"address",value:r},{name:"amount",type:"integer",gt:0,value:e},{name:"resource",type:"resource",value:t,msg:'Invalid resource provided: Expected "BANDWIDTH" or "ENERGY"'}]);const n={owner_address:(0,s.toHex)(r),frozen_balance:parseInt(e)};"BANDWIDTH"!==t&&(n.resource=t);const a=(0,d.getTransactionOptions)(o);return(0,d.createTransaction)(this.tronWeb,u.ContractType.FreezeBalanceV2Contract,n,o?.permissionId,a)}async unfreezeBalanceV2(e=0,t="BANDWIDTH",r=this.tronWeb.defaultAddress.hex,o={}){this.validator.notValid([{name:"origin",type:"address",value:r},{name:"amount",type:"integer",gt:0,value:e},{name:"resource",type:"resource",value:t,msg:'Invalid resource provided: Expected "BANDWIDTH" or "ENERGY"'}]);const n={owner_address:(0,s.toHex)(r),unfreeze_balance:parseInt(e)};"BANDWIDTH"!==t&&(n.resource=t);const a=(0,d.getTransactionOptions)(o);return(0,d.createTransaction)(this.tronWeb,u.ContractType.UnfreezeBalanceV2Contract,n,o?.permissionId,a)}async cancelUnfreezeBalanceV2(e=this.tronWeb.defaultAddress.hex,t={}){this.validator.notValid([{name:"origin",type:"address",value:e}]);const r={owner_address:(0,s.toHex)(e)},o=(0,d.getTransactionOptions)(t);return(0,d.createTransaction)(this.tronWeb,u.ContractType.CancelAllUnfreezeV2Contract,r,t?.permissionId,o)}async delegateResource(e=0,t,r="BANDWIDTH",o=this.tronWeb.defaultAddress.hex,n=!1,a,i={}){if(this.validator.notValid([{name:"amount",type:"integer",gt:0,value:e},{name:"resource",type:"resource",value:r,msg:'Invalid resource provided: Expected "BANDWIDTH" or "ENERGY"'},{name:"receiver",type:"address",value:t},{name:"origin",type:"address",value:o},{name:"lock",type:"boolean",value:n},{name:"lock period",type:"integer",gte:0,value:a,optional:!0}]),(0,s.toHex)(t)===(0,s.toHex)(o))throw new Error("Receiver address must not be the same as owner address");const l={owner_address:(0,s.toHex)(o),receiver_address:(0,s.toHex)(t),balance:parseInt(e)};"BANDWIDTH"!==r&&(l.resource=r),n&&(l.lock=n,(0,c.isNotNullOrUndefined)(a)&&(l.lock_period=a));const p=(0,d.getTransactionOptions)(i);return(0,d.createTransaction)(this.tronWeb,u.ContractType.DelegateResourceContract,l,i?.permissionId,p)}async undelegateResource(e=0,t,r="BANDWIDTH",o=this.tronWeb.defaultAddress.hex,n={}){if(this.validator.notValid([{name:"origin",type:"address",value:o},{name:"receiver",type:"address",value:t},{name:"amount",type:"integer",gt:0,value:e},{name:"resource",type:"resource",value:r,msg:'Invalid resource provided: Expected "BANDWIDTH" or "ENERGY"'}]),(0,s.toHex)(t)===(0,s.toHex)(o))throw new Error("Receiver address must not be the same as owner address");const a={owner_address:(0,s.toHex)(o),receiver_address:(0,s.toHex)(t),balance:parseInt(e)};"BANDWIDTH"!==r&&(a.resource=r);const i=(0,d.getTransactionOptions)(n);return(0,d.createTransaction)(this.tronWeb,u.ContractType.UnDelegateResourceContract,a,n?.permissionId,i)}async withdrawExpireUnfreeze(e=this.tronWeb.defaultAddress.hex,t={}){this.validator.notValid([{name:"origin",type:"address",value:e}]);const r={owner_address:(0,s.toHex)(e)},o=(0,d.getTransactionOptions)(t);return(0,d.createTransaction)(this.tronWeb,u.ContractType.WithdrawExpireUnfreezeContract,r,t?.permissionId,o)}async withdrawBlockRewards(e=this.tronWeb.defaultAddress.hex,t={}){this.validator.notValid([{name:"origin",type:"address",value:e}]);const r={owner_address:(0,s.toHex)(e)},o=(0,d.getTransactionOptions)(t);return(0,d.createTransaction)(this.tronWeb,u.ContractType.WithdrawBalanceContract,r,t?.permissionId,o)}async applyForSR(e=this.tronWeb.defaultAddress.hex,t="",r={}){this.validator.notValid([{name:"origin",type:"address",value:e},{name:"url",type:"url",value:t,msg:"Invalid url provided"},{name:"url",type:"string",value:t,lte:256,msg:"Invalid url provided"}]);const o={owner_address:(0,s.toHex)(e),url:(0,d.fromUtf8)(t)},n=(0,d.getTransactionOptions)(r);return(0,d.createTransaction)(this.tronWeb,u.ContractType.WitnessCreateContract,o,r?.permissionId,n)}async vote(e={},t=this.tronWeb.defaultAddress.hex,r={}){this.validator.notValid([{name:"voter",type:"address",value:t},{name:"votes",type:"notEmptyObject",value:e}]);const o=Object.entries(e);for(const[e,t]of o)this.validator.notValid([{name:"SR",type:"address",value:e},{name:"vote count",type:"integer",gt:0,value:t,msg:"Invalid vote count provided for SR: "+e}]);const n=o.map((([e,t])=>({vote_address:(0,s.toHex)(e),vote_count:parseInt(t)}))),a={owner_address:(0,s.toHex)(t),votes:n},i=(0,d.getTransactionOptions)(r);return(0,d.createTransaction)(this.tronWeb,u.ContractType.VoteWitnessContract,a,r?.permissionId,i)}async createSmartContract(e={},t=this.tronWeb.defaultAddress.hex){const r=e.feeLimit||this.tronWeb.feeLimit;let o=e.userFeePercentage;"number"==typeof o||o||(o=100);const i=e.originEnergyLimit||1e7,l=e.callValue||0,p=e.tokenValue,g=e.tokenId||e.token_id;let{abi:f}=e;const{parameters:y=[]}=e;let b="";const{bytecode:h=!1,name:T=""}=e;if(f&&(0,c.isString)(f))try{f=JSON.parse(f)}catch{throw new Error("Invalid options.abi provided")}const W=f;let P=W;if(W.entrys&&(P=W.entrys),!(0,c.isArray)(P))throw new Error("Invalid options.abi provided");const m=P.some((e=>"constructor"===e.type&&"payable"===e.stateMutability.toLowerCase()));if(this.validator.notValid([{name:"bytecode",type:"hex",value:h},{name:"feeLimit",type:"integer",value:r,gt:0},{name:"callValue",type:"integer",value:l,gte:0},{name:"userFeePercentage",type:"integer",value:o,gte:0,lte:100},{name:"originEnergyLimit",type:"integer",value:i,gte:0,lte:1e7},{name:"parameters",type:"array",value:y},{name:"issuer",type:"address",value:t},{name:"tokenValue",type:"integer",value:p,gte:0,optional:!0},{name:"tokenId",type:"integer",value:g,gte:0,optional:!0}]),!m&&(l>0||p>0))throw new Error("When contract is not payable, options.callValue and options.tokenValue must be 0");const{rawParameter:A,funcABIV2:B,parametersV2:C}=e;if(A&&(0,c.isString)(A))b=A.replace(/^(0x)/,"");else if(B)b=(0,a.encodeParamsV2ByABI)(B,C).replace(/^(0x)/,"");else{let e=P.find((e=>"constructor"===e.type));if(void 0!==e&&e){const t=new n.AbiCoder,r=[],o=[];if(e=e.inputs,y.length!=e.length)throw new Error(`constructor needs ${e.length} but ${y.length} provided`);for(let t=0;t<y.length;t++){let n=e[t].type,a=y[t];if(!n||!(0,c.isString)(n)||!n.length)throw new Error("Invalid parameter type provided: "+n);const i=e=>(0,c.isArray)(e)?e.map((e=>i(e))):(0,s.toHex)(e).replace(s.ADDRESS_PREFIX_REGEX,"0x");"address"===n||"address["===n.match(/^([^\x5b]*)(\x5b|$)/)?.[0]?a=i(a):/trcToken/.test(n)&&(n=n.replace(/trcToken/,"uint256")),r.push(n),o.push(a)}try{b=t.encode(r,o).replace(/^(0x)/,"")}catch(e){throw new Error(e)}}else b=""}const w={owner_address:(0,s.toHex)(t),fee_limit:parseInt(r),call_value:parseInt(l),consume_user_resource_percent:o,origin_energy_limit:i,abi:JSON.stringify(f),bytecode:h,parameter:b,name:T};(0,c.isNotNullOrUndefined)(p)&&(w.call_token_value=parseInt(p)),(0,c.isNotNullOrUndefined)(g)&&(w.token_id=parseInt(g));const E={};E.owner_address=w.owner_address,(0,c.isNotNullOrUndefined)(w.call_token_value)&&(E.call_token_value=w.call_token_value),(0,c.isNotNullOrUndefined)(w.token_id)&&(E.token_id=w.token_id);const I=E.new_contract={};w.abi?I.abi={entrys:JSON.parse(w.abi)}:I.abi={},w.call_value&&(I.call_value=w.call_value),I.consume_user_resource_percent=w.consume_user_resource_percent,I.origin_energy_limit=w.origin_energy_limit,I.origin_address=w.origin_address??w.owner_address,w.bytecode+w.parameter&&(I.bytecode=(w.bytecode+w.parameter).replace(/^0x/,"")),(0,c.isNotNullOrUndefined)(w.name)&&(I.name=w.name);const F=(0,d.getTransactionOptions)(e),M=await(0,d.createTransaction)(this.tronWeb,u.ContractType.CreateSmartContract,E,e?.permissionId,{...F,fee_limit:w.fee_limit});return M.contract_address=(0,d.genContractAddress)(w.owner_address,M.txID),M}async triggerSmartContract(e,t,r,o,n){const s=[e,t,r,o,n];return"object"!=typeof s[2]&&(s[2]={feeLimit:s[2],callValue:s[3]},s.splice(3,1)),s[2]?.txLocal?this._triggerSmartContractLocal(...s):this._triggerSmartContract(...s)}async triggerConstantContract(e,t,r={},o=[],n=this.tronWeb.defaultAddress.hex){return r._isConstant=!0,this._triggerSmartContract(e,t,r,o,n)}async triggerConfirmedConstantContract(e,t,r={},o=[],n=this.tronWeb.defaultAddress.hex){return r._isConstant=!0,r.confirmed=!0,this._triggerSmartContract(e,t,r,o,n)}async estimateEnergy(e,t,r={},o=[],n=this.tronWeb.defaultAddress.hex){return r.estimateEnergy=!0,await this._triggerSmartContract(e,t,r,o,n)}async deployConstantContract(e={input:"",ownerAddress:""}){const{input:t,ownerAddress:r,tokenId:o,tokenValue:n,callValue:a=0}=e;this.validator.notValid([{name:"input",type:"not-empty-string",value:t},{name:"callValue",type:"integer",value:a,gte:0},{name:"owner",type:"address",value:r},{name:"tokenValue",type:"integer",value:n,gte:0,optional:!0},{name:"tokenId",type:"integer",value:o,gte:0,optional:!0}]);const i={data:t,owner_address:(0,s.toHex)(r),call_value:a};o&&(i.token_id=o),n&&(i.call_token_value=n);const c=`wallet${e.confirmed?"solidity":""}/estimateenergy`,u=await this.tronWeb[e.confirmed?"solidityNode":"fullNode"].request(c,i,"post");if(u.Error)throw new Error(u.Error);if(u.result&&u.result.message)throw new Error(this.tronWeb.toUtf8(u.result.message));return u}_getTriggerSmartContractArgs(e,t,r,o,i,u,d,l,p){const g={contract_address:(0,s.toHex)(e),owner_address:(0,s.toHex)(i)};if(t&&(0,c.isString)(t)){let e;if(t=t.replace(/\s*/g,""),o.length){const t=new n.AbiCoder;let r=[];const a=[];for(let e=0;e<o.length;e++){let{value:t}=o[e];const{type:n}=o[e];if(!n||!(0,c.isString)(n)||!n.length)throw new Error("Invalid parameter type provided: "+n);const i=e=>(0,c.isArray)(e)?e.map((e=>i(e))):(0,s.toHex)(e).replace(s.ADDRESS_PREFIX_REGEX,"0x");("address"===n||"address["===n.match(/^([^\x5b]*)(\x5b|$)/)?.[0])&&(t=i(t)),r.push(n),a.push(t)}try{r=r.map((e=>(/trcToken/.test(e)&&(e=e.replace(/trcToken/,"uint256")),e))),e=t.encode(r,a).replace(/^(0x)/,"")}catch(e){throw new Error(e)}}else e="";r.funcABIV2&&(e=(0,a.encodeParamsV2ByABI)(r.funcABIV2,r.parametersV2).replace(/^(0x)/,"")),r.shieldedParameter&&(0,c.isString)(r.shieldedParameter)&&(e=r.shieldedParameter.replace(/^(0x)/,"")),r.rawParameter&&(0,c.isString)(r.rawParameter)&&(e=r.rawParameter.replace(/^(0x)/,"")),g.function_selector=t,g.parameter=e}else r.input&&(g.data=r.input);return g.call_value=parseInt(l),(0,c.isNotNullOrUndefined)(u)&&(g.call_token_value=parseInt(u)),(0,c.isNotNullOrUndefined)(d)&&(g.token_id=parseInt(d)),r._isConstant||r.estimateEnergy||(g.fee_limit=parseInt(p)),r.permissionId&&(g.Permission_id=r.permissionId),g}async _triggerSmartContractLocal(e,t,r={},o=[],s=this.tronWeb.defaultAddress.hex){const{tokenValue:a,tokenId:i,callValue:c,feeLimit:l}=Object.assign({callValue:0,feeLimit:this.tronWeb.feeLimit},r);this.validator.notValid([{name:"feeLimit",type:"integer",value:l,gt:0},{name:"callValue",type:"integer",value:c,gte:0},{name:"parameters",type:"array",value:o},{name:"contract",type:"address",value:e},{name:"issuer",type:"address",value:s,optional:!0},{name:"tokenValue",type:"integer",value:a,gte:0,optional:!0},{name:"tokenId",type:"integer",value:i,gte:0,optional:!0}]);const p=this._getTriggerSmartContractArgs(e,t,r,o,s,a,i,c,l);p.function_selector&&(p.data=(0,n.keccak256)(Buffer.from(p.function_selector,"utf-8")).toString().substring(2,10)+p.parameter);const g={data:p.data,owner_address:p.owner_address,contract_address:p.contract_address};p.call_value&&(g.call_value=p.call_value),p.call_token_value&&(g.call_token_value=p.call_token_value),p.token_id&&(g.token_id=p.token_id);const f=(0,d.getTransactionOptions)(r);return{result:{result:!0},transaction:await(0,d.createTransaction)(this.tronWeb,u.ContractType.TriggerSmartContract,g,r.permissionId,{...f,fee_limit:p.fee_limit})}}async _triggerSmartContract(e,t,r={},o=[],n=this.tronWeb.defaultAddress.hex){const{tokenValue:s,tokenId:a,callValue:i,feeLimit:c}=Object.assign({callValue:0,feeLimit:this.tronWeb.feeLimit},r);this.validator.notValid([{name:"feeLimit",type:"integer",value:c,gt:0},{name:"callValue",type:"integer",value:i,gte:0},{name:"parameters",type:"array",value:o},{name:"contract",type:"address",value:e},{name:"issuer",type:"address",value:n,optional:!0},{name:"tokenValue",type:"integer",value:s,gte:0,optional:!0},{name:"tokenId",type:"integer",value:a,gte:0,optional:!0}]);const u=this._getTriggerSmartContractArgs(e,t,r,o,n,s,a,i,c);let l="triggersmartcontract";r._isConstant?l="triggerconstantcontract":r.estimateEnergy&&(l="estimateenergy"),l=`wallet${r.confirmed?"solidity":""}/${l}`;const p=await this.tronWeb[r.confirmed?"solidityNode":"fullNode"].request(l,u,"post");return(0,d.resultManagerTriggerSmartContract)(p,u,r)}async clearABI(e,t=this.tronWeb.defaultAddress.hex,r={}){if(!o.TronWeb.isAddress(e))throw new Error("Invalid contract address provided");if(!o.TronWeb.isAddress(t))throw new Error("Invalid owner address provided");const n={contract_address:(0,s.toHex)(e),owner_address:(0,s.toHex)(t)};this.tronWeb.trx.cache.contracts[e]&&delete this.tronWeb.trx.cache.contracts[e];const a=(0,d.getTransactionOptions)(r);return(0,d.createTransaction)(this.tronWeb,u.ContractType.ClearABIContract,n,r?.permissionId,a)}async updateBrokerage(e,t=this.tronWeb.defaultAddress.hex,r={}){if(!(0,c.isNotNullOrUndefined)(e))throw new Error("Invalid brokerage provided");if(!(0,c.isInteger)(e)||e<0||e>100)throw new Error("Brokerage must be an integer between 0 and 100");if(!o.TronWeb.isAddress(t))throw new Error("Invalid owner address provided");const n={brokerage:parseInt(e),owner_address:(0,s.toHex)(t)},a=(0,d.getTransactionOptions)(r);return(0,d.createTransaction)(this.tronWeb,u.ContractType.UpdateBrokerageContract,n,r?.permissionId,a)}async createToken(e={},t=this.tronWeb.defaultAddress.hex){const{name:r=!1,abbreviation:o=!1,description:n="",url:a=!1,totalSupply:i=0,trxRatio:l=1,tokenRatio:p=1,saleStart:g=Date.now(),saleEnd:f=!1,freeBandwidth:y=0,freeBandwidthLimit:b=0,frozenAmount:h=0,frozenDuration:T=0,voteScore:W,precision:P}=e;if(this.validator.notValid([{name:"Supply amount",type:"positive-integer",value:i},{name:"TRX ratio",type:"positive-integer",value:l},{name:"Token ratio",type:"positive-integer",value:p},{name:"token abbreviation",type:"string",value:o,lte:32,gt:0},{name:"token name",type:"not-empty-string",value:r},{name:"token description",type:"string",value:n,lte:200},{name:"token url",type:"url",value:a},{name:"token url",type:"string",value:a,lte:256},{name:"issuer",type:"address",value:t},{name:"sale start timestamp",type:"integer",value:g,gte:Date.now()},{name:"sale end timestamp",type:"integer",value:f,gt:g},{name:"Frozen supply",type:"integer",value:h,gte:0},{name:"Frozen duration",type:"integer",value:T,gte:0}]),(0,c.isNotNullOrUndefined)(W)&&(!(0,c.isInteger)(W)||W<=0))throw new Error("voteScore must be a positive integer greater than 0");if((0,c.isNotNullOrUndefined)(P)&&(!(0,c.isInteger)(P)||P<0||P>6))throw new Error("precision must be a positive integer >= 0 and <= 6");const m={owner_address:(0,s.toHex)(t),name:(0,d.fromUtf8)(r),abbr:(0,d.fromUtf8)(o),description:(0,d.fromUtf8)(n),url:(0,d.fromUtf8)(a),total_supply:parseInt(i),trx_num:parseInt(l),num:parseInt(p),start_time:parseInt(g),end_time:parseInt(f),frozen_supply:[{frozen_amount:parseInt(h),frozen_days:parseInt(T)}]};["name","abbr","description","url"].forEach((e=>{m[e]||delete m[e]})),parseInt(h)>0||delete m.frozen_supply,y&&!isNaN(parseInt(y))&&parseInt(y)>=0&&(m.free_asset_net_limit=parseInt(y)),b&&!isNaN(parseInt(b))&&parseInt(b)>=0&&(m.public_free_asset_net_limit=parseInt(b)),P&&!isNaN(parseInt(P))&&(m.precision=parseInt(P)),W&&!isNaN(parseInt(W))&&(m.vote_score=parseInt(W));const A=(0,d.getTransactionOptions)(e);return(0,d.createTransaction)(this.tronWeb,u.ContractType.AssetIssueContract,m,e?.permissionId,A)}async createAccount(e,t=this.tronWeb.defaultAddress.hex,r={}){this.validator.notValid([{name:"account",type:"address",value:e},{name:"origin",type:"address",value:t}]);const o={owner_address:(0,s.toHex)(t),account_address:(0,s.toHex)(e)},n=(0,d.getTransactionOptions)(r);return(0,d.createTransaction)(this.tronWeb,u.ContractType.AccountCreateContract,o,r?.permissionId,n)}async updateAccount(e,t=this.tronWeb.defaultAddress.hex,r={}){this.validator.notValid([{name:"Name",type:"string",lte:200,gt:0,value:e,msg:"Invalid accountName"},{name:"origin",type:"address",value:t}]);const o={account_name:(0,d.fromUtf8)(e),owner_address:(0,s.toHex)(t)},n=(0,d.getTransactionOptions)(r);return(0,d.createTransaction)(this.tronWeb,u.ContractType.AccountUpdateContract,o,r?.permissionId,n)}async setAccountId(e,t=this.tronWeb.defaultAddress.hex,r={}){e&&(0,c.isString)(e)&&e.startsWith("0x")&&(e=e.slice(2)),this.validator.notValid([{name:"accountId",type:"hex",value:e},{name:"accountId",type:"string",lte:32,gte:8,value:e},{name:"origin",type:"address",value:t}]);const o={account_id:e,owner_address:(0,s.toHex)(t)},n=(0,d.getTransactionOptions)(r);return(0,d.createTransaction)(this.tronWeb,u.ContractType.SetAccountIdContract,o,r?.permissionId,n)}async updateToken(e={},t=this.tronWeb.defaultAddress.hex){const{description:r="",url:o=!1,freeBandwidth:n=0,freeBandwidthLimit:a=0}=e;this.validator.notValid([{name:"token description",type:"string",value:r,lte:200},{name:"token url",type:"url",value:o},{name:"token url",type:"string",value:o,lte:256},{name:"issuer",type:"address",value:t}]);const i={owner_address:(0,s.toHex)(t),description:(0,d.fromUtf8)(r),url:(0,d.fromUtf8)(o)};n&&!isNaN(parseInt(n))&&parseInt(n)>=0&&(i.new_limit=parseInt(n)),a&&!isNaN(parseInt(a))&&parseInt(a)>=0&&(i.new_public_limit=parseInt(a));const c=(0,d.getTransactionOptions)(e);return(0,d.createTransaction)(this.tronWeb,u.ContractType.UpdateAssetContract,i,e?.permissionId,c)}async sendAsset(e,t=0,r,o=this.tronWeb.defaultAddress.hex,n={}){return this.sendToken(e,t,r,o,n)}async purchaseAsset(e,t,r=0,o=this.tronWeb.defaultAddress.hex,n={}){return this.purchaseToken(e,t,r,o,n)}async createAsset(e,t){return this.createToken(e,t)}async updateAsset(e={},t=this.tronWeb.defaultAddress.hex){return this.updateToken(e,t)}async createProposal(e,t=this.tronWeb.defaultAddress.hex,r={}){this.validator.notValid([{name:"issuer",type:"address",value:t}]);const o="Invalid proposal parameters provided";if(!e)throw new Error(o);const n=(0,c.isArray)(e)?e:[e];for(const e of n)if(!(0,c.isObject)(e))throw new Error(o);const a={owner_address:(0,s.toHex)(t),parameters:n},i=(0,d.getTransactionOptions)(r);return(0,d.createTransaction)(this.tronWeb,u.ContractType.ProposalCreateContract,a,r?.permissionId,i)}async deleteProposal(e,t=this.tronWeb.defaultAddress.hex,r={}){this.validator.notValid([{name:"issuer",type:"address",value:t},{name:"proposalID",type:"integer",value:e,gte:0}]);const o={owner_address:(0,s.toHex)(t),proposal_id:parseInt(e)},n=(0,d.getTransactionOptions)(r);return(0,d.createTransaction)(this.tronWeb,u.ContractType.ProposalDeleteContract,o,r?.permissionId,n)}async voteProposal(e,t=!1,r=this.tronWeb.defaultAddress.hex,o={}){this.validator.notValid([{name:"voter",type:"address",value:r},{name:"proposalID",type:"integer",value:e,gte:0},{name:"has approval",type:"boolean",value:t}]);const n={owner_address:(0,s.toHex)(r),proposal_id:parseInt(e),is_add_approval:t},a=(0,d.getTransactionOptions)(o);return(0,d.createTransaction)(this.tronWeb,u.ContractType.ProposalApproveContract,n,o?.permissionId,a)}async createTRXExchange(e,t,r,o=this.tronWeb.defaultAddress.hex,n={}){this.validator.notValid([{name:"owner",type:"address",value:o},{name:"token name",type:"not-empty-string",value:e},{name:"token balance",type:"positive-integer",value:t},{name:"trx balance",type:"positive-integer",value:r}]);const a={owner_address:(0,s.toHex)(o),first_token_id:(0,d.fromUtf8)(e),first_token_balance:t,second_token_id:"5f",second_token_balance:r},i=(0,d.getTransactionOptions)(n);return(0,d.createTransaction)(this.tronWeb,u.ContractType.ExchangeCreateContract,a,n?.permissionId,i)}async createTokenExchange(e,t,r,o,n=this.tronWeb.defaultAddress.hex,a={}){this.validator.notValid([{name:"owner",type:"address",value:n},{name:"first token name",type:"not-empty-string",value:e},{name:"second token name",type:"not-empty-string",value:r},{name:"first token balance",type:"positive-integer",value:t},{name:"second token balance",type:"positive-integer",value:o}]);const i={owner_address:(0,s.toHex)(n),first_token_id:(0,d.fromUtf8)(e),first_token_balance:t,second_token_id:(0,d.fromUtf8)(r),second_token_balance:o},c=(0,d.getTransactionOptions)(a);return(0,d.createTransaction)(this.tronWeb,u.ContractType.ExchangeCreateContract,i,a?.permissionId,c)}async injectExchangeTokens(e,t,r,o=this.tronWeb.defaultAddress.hex,n={}){this.validator.notValid([{name:"owner",type:"address",value:o},{name:"token name",type:"not-empty-string",value:t},{name:"token amount",type:"integer",value:r,gte:1},{name:"exchangeID",type:"integer",value:e,gte:0}]);const a={owner_address:(0,s.toHex)(o),exchange_id:parseInt(e),token_id:(0,d.fromUtf8)(t),quant:parseInt(r)},i=(0,d.getTransactionOptions)(n);return(0,d.createTransaction)(this.tronWeb,u.ContractType.ExchangeInjectContract,a,n?.permissionId,i)}async withdrawExchangeTokens(e,t,r,o=this.tronWeb.defaultAddress.hex,n={}){this.validator.notValid([{name:"owner",type:"address",value:o},{name:"token name",type:"not-empty-string",value:t},{name:"token amount",type:"integer",value:r,gte:1},{name:"exchangeID",type:"integer",value:e,gte:0}]);const a={owner_address:(0,s.toHex)(o),exchange_id:parseInt(e),token_id:(0,d.fromUtf8)(t),quant:parseInt(r)},i=(0,d.getTransactionOptions)(n);return(0,d.createTransaction)(this.tronWeb,u.ContractType.ExchangeWithdrawContract,a,n?.permissionId,i)}async tradeExchangeTokens(e,t,r,n,a=this.tronWeb.defaultAddress.hex,i={}){this.validator.notValid([{name:"owner",type:"address",value:a},{name:"token name",type:"not-empty-string",value:t},{name:"tokenAmountSold",type:"integer",value:r,gte:1},{name:"tokenAmountExpected",type:"integer",value:n,gte:1},{name:"exchangeID",type:"integer",value:e,gte:0}]);const c={owner_address:(0,s.toHex)(a),exchange_id:parseInt(e),token_id:o.TronWeb.fromAscii(t).replace(/^0x/,""),quant:parseInt(r),expected:parseInt(n)},l=(0,d.getTransactionOptions)(i);return(0,d.createTransaction)(this.tronWeb,u.ContractType.ExchangeTransactionContract,c,i?.permissionId,l)}async updateSetting(e,t,r=this.tronWeb.defaultAddress.hex,o={}){this.validator.notValid([{name:"owner",type:"address",value:r},{name:"contract",type:"address",value:e},{name:"userFeePercentage",type:"integer",value:t,gte:0,lte:100}]);const n={owner_address:(0,s.toHex)(r),contract_address:(0,s.toHex)(e),consume_user_resource_percent:t},a=(0,d.getTransactionOptions)(o);return(0,d.createTransaction)(this.tronWeb,u.ContractType.UpdateSettingContract,n,o?.permissionId,a)}async updateEnergyLimit(e,t=0,r=this.tronWeb.defaultAddress.hex,o={}){this.validator.notValid([{name:"owner",type:"address",value:r},{name:"contract",type:"address",value:e},{name:"originEnergyLimit",type:"integer",value:t,gte:0,lte:1e7}]);const n={owner_address:(0,s.toHex)(r),contract_address:(0,s.toHex)(e),origin_energy_limit:t},a=(0,d.getTransactionOptions)(o);return(0,d.createTransaction)(this.tronWeb,u.ContractType.UpdateEnergyLimitContract,n,o?.permissionId,a)}checkPermissions(e,t){if(e){if(e.type!==t||!e.permission_name||!(0,c.isString)(e.permission_name)||!(0,c.isInteger)(e.threshold)||e.threshold<1||!e.keys)return!1;for(const r of e.keys)if(!o.TronWeb.isAddress(r.address)||!(0,c.isInteger)(r.weight)||r.weight>e.threshold||r.weight<1||2===t&&!e.operations)return!1}return!0}async updateAccountPermissions(e=this.tronWeb.defaultAddress.hex,t,r,n,a={}){if(!o.TronWeb.isAddress(e))throw new Error("Invalid ownerAddress provided");if(!this.checkPermissions(t,0))throw new Error("Invalid ownerPermissions provided");if(!this.checkPermissions(r,1))throw new Error("Invalid witnessPermissions provided");Array.isArray(n)||(n=[n]);for(const e of n)if(!this.checkPermissions(e,2))throw new Error("Invalid activesPermissions provided");const i={owner_address:(0,s.toHex)(e)};if(t){const e=(0,d.deepCopyJson)(t);"type"in e&&delete e.type,e.keys=e.keys?.map((({address:e,weight:t})=>({address:this.tronWeb.address.toHex(e),weight:t}))),i.owner=e}if(r){const e=(0,d.deepCopyJson)(r);e.type="Witness",e.keys=e.keys.map((({address:e,weight:t})=>({address:this.tronWeb.address.toHex(e),weight:t}))),i.witness=e}if(n){const e=(0,d.deepCopyJson)(n);e.forEach((e=>{e.type="Active"})),e.forEach((e=>{e.keys=e.keys.map((({address:e,weight:t})=>({address:this.tronWeb.address.toHex(e),weight:t})))})),i.actives=e}const c=(0,d.getTransactionOptions)(a);return(0,d.createTransaction)(this.tronWeb,u.ContractType.AccountPermissionUpdateContract,i,a?.permissionId,c)}async newTxID(e,t={}){if(t?.txLocal){const t=e.raw_data.contract[0];try{const r=await(0,d.createTransaction)(this.tronWeb,t.type,t.parameter.value,t.Permission_id,{fee_limit:e.raw_data.fee_limit,data:e.raw_data.data,ref_block_bytes:e.raw_data.ref_block_bytes,ref_block_hash:e.raw_data.ref_block_hash,expiration:e.raw_data.expiration,timestamp:e.raw_data.timestamp});return r.signature=e.signature,r.visible=e.visible,r}catch(e){throw new Error("Error generating a new transaction id.")}}try{const t=await this.tronWeb.fullNode.request("wallet/getsignweight",e,"post");return"boolean"==typeof e.visible&&(t.transaction.transaction.visible=e.visible),(0,d.resultManager)(t.transaction.transaction,{...e.raw_data.contract[0].parameter.value,Permission_id:e.raw_data.contract[0].Permission_id},{data:e.raw_data.data,fee_limit:e.raw_data.fee_limit})}catch(e){throw new Error("Error generating a new transaction id.")}}async alterTransaction(e,t={}){if(Reflect.has(e,"signature"))throw new Error("You can not extend the expiration of a signed transaction.");if(t.data){if("hex"!==t.dataFormat&&(t.data=o.TronWeb.toHex(t.data)),t.data=t.data.replace(/^0x/,""),0===t.data.length)throw new Error("Invalid data provided");e.raw_data.data=t.data}if(t.extension){if(t.extension=parseInt(1e3*t.extension),isNaN(t.extension)||e.raw_data.expiration+t.extension<=Date.now()+3e3)throw new Error("Invalid extension provided");e.raw_data.expiration+=t.extension}return await this.newTxID(e,{txLocal:t.txLocal})}async extendExpiration(e,t,r={}){return await this.alterTransaction(e,{extension:t,txLocal:r?.txLocal})}async addUpdateData(e,t,r="utf8",o={}){return this.alterTransaction(e,{data:t,dataFormat:r,txLocal:o?.txLocal})}}},5401:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.fromUtf8=function(e){return o.TronWeb.fromUtf8(e).replace(/^0x/,"")},t.deepCopyJson=function(e){return JSON.parse(JSON.stringify(e))},t.resultManager=function(e,t,r){if(e.Error)throw new Error(e.Error);if(e.result&&e.result.message)throw new Error(o.TronWeb.toUtf8(e.result.message));if((0,n.txCheckWithArgs)(e,t,r))return e;throw new Error("Invalid transaction")},t.resultManagerTriggerSmartContract=function(e,t,r){if(e.Error)throw new Error(e.Error);if(e.result&&e.result.message)throw new Error(o.TronWeb.toUtf8(e.result.message));if(!r._isConstant&&!r.estimateEnergy){if((0,n.txCheckWithArgs)(e.transaction,t,r))return e;throw new Error("Invalid transaction")}return e},t.genContractAddress=function(e,t){return"41"+(0,s.keccak256)(Buffer.from(t+e,"hex")).toString().substring(2).slice(24)},t.getHeaderInfo=a,t.createTransaction=async function(e,t,r,o,s={}){const c={visible:!1,txID:"",raw_data_hex:"",raw_data:{contract:[{parameter:{value:r,type_url:`type.googleapis.com/protocol.${t}`},type:t}],...i(s)?{}:await a(e.fullNode),...s}};o&&(c.raw_data.contract[0].Permission_id=o);const u=(0,n.txJsonToPb)(c);return c.txID=(0,n.txPbToTxID)(u).replace(/^0x/,""),c.raw_data_hex=(0,n.txPbToRawDataHex)(u).toLowerCase(),c},t.getTransactionOptions=function(e={}){const t={};return i(e.blockHeader)&&(t.ref_block_bytes=e.blockHeader.ref_block_bytes,t.ref_block_hash=e.blockHeader.ref_block_hash,t.expiration=e.blockHeader.expiration,t.timestamp=e.blockHeader.timestamp),t};const o=r(5562),n=r(8931),s=r(9193);function a(e){return e.request("wallet/getblock",{detail:!1},"post").then((e=>({ref_block_bytes:e.block_header.raw_data.number.toString(16).slice(-4).padStart(4,"0"),ref_block_hash:e.blockID.slice(16,32),expiration:e.block_header.raw_data.timestamp+6e4,timestamp:e.block_header.raw_data.timestamp})))}function i(e={}){if(void 0===e.ref_block_bytes&&void 0===e.ref_block_hash&&void 0===e.expiration&&void 0===e.timestamp)return!1;if("string"!=typeof e.ref_block_bytes)throw new Error("Invalid ref_block_bytes provided.");if("string"!=typeof e.ref_block_hash)throw new Error("Invalid ref_block_hash provided.");if("number"!=typeof e.expiration)throw new Error("Invalid expiration provided.");if("number"!=typeof e.timestamp)throw new Error("Invalid timestamp provided.");return!0}},5884:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Method=t.Contract=void 0;const o=r(5584),n=r(5562),s=o.__importDefault(r(6219)),a=r(7759);t.Contract=class{tronWeb;abi;address;eventListener;bytecode;deployed;lastBlock;methods;methodInstances;props;constructor(e,t=[],r){if(!(e&&e instanceof n.TronWeb))throw new Error("Expected instance of TronWeb");this.tronWeb=e,this.address=r,this.abi=t,this.eventListener=!1,this.bytecode=!1,this.deployed=!1,this.lastBlock=!1,this.methods={},this.methodInstances={},this.props=[],s.default.address.isAddress(r)?this.deployed=!0:this.address=!1,this.loadAbi(t)}hasProperty(e){return this.hasOwnProperty(e)||this.__proto__.hasOwnProperty(e)}loadAbi(e){this.abi=e,this.methods={},this.props.forEach((e=>delete this[e])),e.forEach((e=>{if(!e.type||/constructor|error/i.test(e.type))return;const t=new a.Method(this,e),r=t.onMethod.bind(t),{name:o,functionSelector:n,signature:s}=t;this.methods[o]=r,this.methods[n]=r,this.methods[s]=r,this.methodInstances[o]=t,this.methodInstances[n]=t,this.methodInstances[s]=t,this.hasProperty(o)||(this[o]=r,this.props.push(o)),this.hasProperty(n)||(this[n]=r,this.props.push(n)),this.hasProperty(s)||(this[s]=r,this.props.push(s))}))}decodeInput(e){const t=e.substring(0,8),r=e.substring(8);if(!this.methodInstances[t])throw new Error("Contract method "+t+" not found");return{name:this.methodInstances[t].name,params:this.methodInstances[t].decodeInput(r)}}async new(e,t=this.tronWeb.defaultPrivateKey){const r=this.tronWeb.address.fromPrivateKey(t),o=await this.tronWeb.transactionBuilder.createSmartContract(e,r),n=await this.tronWeb.trx.sign(o,t),a=await this.tronWeb.trx.sendRawTransaction(n);if(a.code)throw{error:a.code,message:this.tronWeb.toUtf8(a.message)};return await s.default.sleep(3e3),this.at(n.contract_address)}async at(e){try{const t=await this.tronWeb.trx.getContract(e);if(!t.contract_address)throw new Error("Unknown error: "+JSON.stringify(t,null,2));return this.address=t.contract_address,this.bytecode=t.bytecode,this.deployed=!0,this.loadAbi(t.abi&&t.abi.entrys?t.abi.entrys:[]),this}catch(e){if(e.toString().includes("does not exist"))throw new Error("Contract has not been deployed on the network");throw new Error(e)}}};var i=r(7759);Object.defineProperty(t,"Method",{enumerable:!0,get:function(){return i.Method}})},7759:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Method=void 0;const o=r(5584).__importDefault(r(6219)),n=r(8557),s=r(7154),a=(e,t)=>(0,n.decodeParamsV2ByABI)(e,t);t.Method=class{tronWeb;contract;abi;name;inputs;outputs;functionSelector;signature;defaultOptions;constructor(e,t){this.tronWeb=e.tronWeb,this.contract=e,this.abi=t,this.name=t.name||t.type,this.inputs=t.inputs||[],this.outputs=[],"outputs"in t&&t.outputs&&(this.outputs=t.outputs),this.functionSelector=(e=>{if("stateMutability"in e&&(e.stateMutability=e.stateMutability?e.stateMutability.toLowerCase():"nonpayable"),e.type=e.type?e.type.toLowerCase():"","fallback"===e.type||"receive"===e.type)return"0x";const t=new o.default.ethersUtils.Interface([e]);let r;if(r="event"===e.type?t.getEvent(e.name):t.getFunction(e.name),r)return r.format("sighash");throw new Error("unknown function")})(t),this.signature=(0,s.sha3)(this.functionSelector,!1).slice(0,8),this.defaultOptions={feeLimit:this.tronWeb.feeLimit,callValue:0,userFeePercentage:100,shouldPollResponse:!1}}decodeInput(e){const t=JSON.parse(JSON.stringify(this.abi));return t.outputs=t.inputs,a(t,"0x"+e)}onMethod(...e){let t="";return this.abi&&!/event/i.test(this.abi.type)&&(t=(0,n.encodeParamsV2ByABI)(this.abi,e)),{call:async(e={})=>(e={...e,rawParameter:t},await this._call([],[],e)),send:async(e={},r=this.tronWeb.defaultPrivateKey)=>(e={...e,rawParameter:t},await this._send([],[],e,r))}}async _call(e,t,r={}){if(e.length!==t.length)throw new Error("Invalid argument count provided");if(!this.contract.address)throw new Error("Smart contract is missing address");if(!this.contract.deployed)throw new Error("Calling smart contracts requires you to load the contract first");if("stateMutability"in this.abi){const{stateMutability:e}=this.abi;if(e&&!["pure","view"].includes(e.toLowerCase()))throw new Error(`Methods with state mutability "${e}" must use send()`)}r={...this.defaultOptions,from:this.tronWeb.defaultAddress.hex,...r,_isConstant:!0};const n=t.map(((t,r)=>({type:e[r],value:t}))),s=await this.tronWeb.transactionBuilder.triggerSmartContract(this.contract.address,this.functionSelector,r,n,r.from?this.tronWeb.address.toHex(r.from):void 0);if(!o.default.hasProperty(s,"constant_result"))throw new Error("Failed to execute");const i=s.constant_result[0].length;if(0===i||i%64==8){let e="The call has been reverted or has thrown an error.";if(0!==i){e+=" Error message: ";let t="";const r=s.constant_result[0].substring(8);for(let e=0;e<i-8;e+=64)t+=this.tronWeb.toUtf8(r.substring(e,e+64));e+=t.replace(/(\u0000|\u000b|\f)+/g," ").replace(/ +/g," ").replace(/\s+$/g,"")}throw new Error(e)}let c=a(this.abi,"0x"+s.constant_result[0]);return 1===c.length&&1===Object.keys(c).length&&(c=c[0]),c}async _send(e,t,r={},n=this.tronWeb.defaultPrivateKey){if(e.length!==t.length)throw new Error("Invalid argument count provided");if(!this.contract.address)throw new Error("Smart contract is missing address");if(!this.contract.deployed)throw new Error("Calling smart contracts requires you to load the contract first");const{stateMutability:s}=this.abi;if(["pure","view"].includes(s.toLowerCase()))throw new Error(`Methods with state mutability "${s}" must use call()`);["payable"].includes(s.toLowerCase())||(r.callValue=0),r={...this.defaultOptions,from:this.tronWeb.defaultAddress.hex,...r};const i=t.map(((t,r)=>({type:e[r],value:t}))),c=n?this.tronWeb.address.fromPrivateKey(n):this.tronWeb.defaultAddress.base58,u=await this.tronWeb.transactionBuilder.triggerSmartContract(this.contract.address,this.functionSelector,r,i,this.tronWeb.address.toHex(c));if(!u.result||!u.result.result)throw new Error("Unknown error: "+JSON.stringify(u,null,2));const d=await this.tronWeb.trx.sign(u.transaction,n);if(!d.signature){if(!n)throw new Error("Transaction was not signed properly");throw new Error("Invalid private key provided")}const l=await this.tronWeb.trx.sendRawTransaction(d);if(l.code){const e={error:l.code,message:l.code};l.message&&(e.message=this.tronWeb.toUtf8(l.message));const t=new Error(e.message);throw t.error=l.code,t}if(!r.shouldPollResponse)return d.txID;const p=async e=>{if(e===(r.pollTimes||20)){const e=new Error("Cannot find result in solidity node");throw e.error="Cannot find result in solidity node",e.transaction=d,e}const t=await this.tronWeb.trx.getTransactionInfo(d.txID);if(!Object.keys(t).length)return await new Promise((e=>setTimeout(e,3e3))),p(e+1);if(t.result&&"FAILED"===t.result){const e=new Error(this.tronWeb.toUtf8(t.resMessage));throw e.error=this.tronWeb.toUtf8(t.resMessage),e.transaction=d,e.output=t,e}if(!o.default.hasProperty(t,"contractResult")){const e=new Error("Failed to execute: "+JSON.stringify(t,null,2));throw e.error="Failed to execute: "+JSON.stringify(t,null,2),e.transaction=d,e.output=t,e}if(r.rawResponse)return t;let n=a(this.abi,"0x"+t.contractResult[0]);return 1===n.length&&1===Object.keys(n).length&&(n=n[0]),r.keepTxID?[d.txID,n]:n};return p(0)}}},3569:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Event=void 0;const o=r(5584),n=r(5562),s=o.__importDefault(r(6219)),a=r(4612);t.Event=class{tronWeb;constructor(e){if(!(e&&e instanceof n.TronWeb))throw new Error("Expected instance of TronWeb");this.tronWeb=e}setServer(e,t="healthcheck"){if(!e)return this.tronWeb.eventServer=void 0;if(s.default.isString(e)&&(e=new a.HttpProvider(e)),!this.tronWeb.isValidProvider(e))throw new Error("Invalid event server provided");this.tronWeb.eventServer=e,this.tronWeb.eventServer.isConnected=()=>this.tronWeb.eventServer.request(t).then((()=>!0)).catch((()=>!1))}async getEventsByContractAddress(e,t={}){const r=Object.assign({limit:20},t),{eventName:o,blockNumber:n,onlyUnconfirmed:a,onlyConfirmed:i,minBlockTimestamp:c,maxBlockTimestamp:u,orderBy:d,fingerprint:l}=r;let{limit:p}=r;if(!this.tronWeb.eventServer)throw new Error("No event server configured");if(!this.tronWeb.isAddress(e))throw new Error("Invalid contract address provided");if(void 0!==c&&!s.default.isInteger(c))throw new Error("Invalid minBlockTimestamp provided");if(void 0!==u&&!s.default.isInteger(u))throw new Error("Invalid maxBlockTimestamp provided");s.default.isInteger(p)&&p>200&&(console.warn("Defaulting to maximum accepted limit: 200"),p=200);const g={};o&&(g.event_name=o),n&&(g.block_number=n),"boolean"==typeof a&&(g.only_unconfirmed=a),"boolean"==typeof i&&(g.only_confirmed=i),c&&(g.min_block_timestamp=c),u&&(g.max_block_timestamp=u),d&&(g.order_by=d),l&&(g.fingerprint=l),s.default.isInteger(p)&&(g.limit=p);const f=await this.tronWeb.eventServer.request(`v1/contracts/${this.tronWeb.address.fromHex(e)}/events?${new URLSearchParams(g).toString()}`);if(f.success)return f;throw new Error(f.error)}async getEventsByTransactionID(e,t={}){if(!this.tronWeb.eventServer)throw new Error("No event server configured");const r={};return"boolean"==typeof t.only_unconfirmed&&(r.only_unconfirmed=t.only_unconfirmed),"boolean"==typeof t.only_confirmed&&(r.only_confirmed=t.only_confirmed),this.tronWeb.eventServer.request(`v1/transactions/${e}/events?${new URLSearchParams(r).toString()}`).then((e=>{if(e.success)return e;throw new Error(JSON.parse(e.error).message)}))}async getEventsByBlockNumber(e,t={}){if(!this.tronWeb.eventServer)throw new Error("No event server configured");const r={};return"boolean"==typeof t.only_confirmed&&(r.only_confirmed=t.only_confirmed),t.limit&&(r.limit=t.limit),t.fingerprint&&(r.fingerprint=t.fingerprint),this.tronWeb.eventServer.request(`v1/blocks/${e}/events?${new URLSearchParams(r).toString()}`).then((e=>{if(e.success)return e;throw new Error(e.error)}))}async getEventsOfLatestBlock(e={}){if(!this.tronWeb.eventServer)throw new Error("No event server configured");const t={};return"boolean"==typeof e.only_confirmed&&(t.only_confirmed=e.only_confirmed),this.tronWeb.eventServer.request(`v1/blocks/latest/events?${new URLSearchParams(t).toString()}`).then((e=>{if(e.success)return e;throw new Error(e.error)}))}}},8050:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Plugin=void 0;const o=r(5584),n=r(5562),s=o.__importDefault(r(6219)),a=o.__importDefault(r(8064));t.Plugin=class{tronWeb;pluginNoOverride;disablePlugins;constructor(e,t={}){if(!(e&&e instanceof n.TronWeb))throw new Error("Expected instance of TronWeb");this.tronWeb=e,this.pluginNoOverride=["register"],this.disablePlugins=!!t.disablePlugins}register(e,t){let r={requires:"0.0.0",components:{}};const o={libs:[],plugged:[],skipped:[],error:void 0};if(this.disablePlugins)return o.error="This instance of TronWeb has plugins disabled.",o;const i=new e(this.tronWeb);if(s.default.isFunction(i.pluginInterface)&&(r=i.pluginInterface(t)),!a.default.satisfies(n.TronWeb.version,r.requires))throw new Error("The plugin is not compatible with this version of TronWeb");if(r.fullClass){const t=i.constructor.name,r=t.substring(0,1).toLowerCase()+t.substring(1);t!==r&&(Object.assign(n.TronWeb,{[t]:e}),Object.assign(this.tronWeb,{[r]:i}),o.libs.push(t))}else for(const e in r.components){if(!this.tronWeb.hasOwnProperty(e))continue;const t=r.components[e],n=this.tronWeb[e].pluginNoOverride||[];for(const r in t)"constructor"===r||this.tronWeb[e][r]&&(n.includes(r)||/^_/.test(r))?o.skipped.push(r):(this.tronWeb[e][r]=t[r].bind(this.tronWeb[e]),o.plugged.push(r))}return o}}},5231:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const o=r(5584).__importDefault(r(8938)),n=r(3331);t.default=class{host;timeout;user;password;headers;statusPage;instance;constructor(e,t=3e4,r="",s="",a={},i="/"){if(!(0,n.isValidURL)(e))throw new Error("Invalid URL provided to HttpProvider");if(isNaN(t)||t<0)throw new Error("Invalid timeout duration provided");if(!(0,n.isObject)(a))throw new Error("Invalid headers object provided");e=e.replace(/\/+$/,""),this.host=e,this.timeout=t,this.user=r,this.password=s,this.headers=a,this.statusPage=i,this.instance=o.default.create({baseURL:e,timeout:t,headers:a,auth:r?{username:r,password:s}:void 0})}setStatusPage(e="/"){this.statusPage=e}async isConnected(e=this.statusPage){return this.request(e).then((e=>(0,n.hasProperties)(e,"blockID","block_header"))).catch((()=>!1))}request(e,t={},r="get"){return r=r.toLowerCase(),this.instance.request({data:"post"==r&&Object.keys(t).length?t:null,params:"get"==r&&t,url:e,method:r}).then((({data:e})=>e))}}},4612:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.HttpProvider=t.providers=void 0;const o=r(5584).__importDefault(r(5231));t.HttpProvider=o.default,t.providers={HttpProvider:o.default}},983:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Trx=void 0;const o=r(5584),n=r(5562),s=o.__importDefault(r(6219)),a=r(9193),i=r(9055),c=r(7035),u=r(8931),d=r(7154),l="TRON Signed Message:\n32",p="Ethereum Signed Message:\n32";function g(e){return n.TronWeb.address.toHex(e)}class f{tronWeb;cache;validator;signMessage;sendAsset;send;sendTrx;broadcast;broadcastHex;signTransaction;constructor(e){this.tronWeb=e,this.cache={contracts:{}},this.validator=new c.Validator,this.signMessage=this.sign,this.sendAsset=this.sendToken,this.send=this.sendTransaction,this.sendTrx=this.sendTransaction,this.broadcast=this.sendRawTransaction,this.broadcastHex=this.sendHexTransaction,this.signTransaction=this.sign}_parseToken(e){return{...e,name:this.tronWeb.toUtf8(e.name),abbr:e.abbr&&this.tronWeb.toUtf8(e.abbr),description:e.description&&this.tronWeb.toUtf8(e.description),url:e.url&&this.tronWeb.toUtf8(e.url)}}getCurrentBlock(){return this.tronWeb.fullNode.request("wallet/getnowblock")}getConfirmedCurrentBlock(){return this.tronWeb.solidityNode.request("walletsolidity/getnowblock")}async getBlock(e=this.tronWeb.defaultBlock){if(!1===e)throw new Error("No block identifier provided");return"earliest"==e&&(e=0),"latest"==e?this.getCurrentBlock():isNaN(+e)&&s.default.isHex(e.toString())?this.getBlockByHash(e):this.getBlockByNumber(e)}async getBlockByHash(e){const t=await this.tronWeb.fullNode.request("wallet/getblockbyid",{value:e},"post");if(!Object.keys(t).length)throw new Error("Block not found");return t}async getBlockByNumber(e){if(!s.default.isInteger(e)||e<0)throw new Error("Invalid block number provided");return this.tronWeb.fullNode.request("wallet/getblockbynum",{num:parseInt(e)},"post").then((e=>{if(!Object.keys(e).length)throw new Error("Block not found");return e}))}async getBlockTransactionCount(e=this.tronWeb.defaultBlock){const{transactions:t=[]}=await this.getBlock(e);return t.length}async getTransactionFromBlock(e=this.tronWeb.defaultBlock,t){const{transactions:r}=await this.getBlock(e);if(!r)throw new Error("Transaction not found in block");if(t>=0&&t<r.length)return r[t];throw new Error("Invalid transaction index provided")}async getTransactionsFromBlock(e=this.tronWeb.defaultBlock){const{transactions:t}=await this.getBlock(e);if(!t)throw new Error("Transaction not found in block");return t}async getTransaction(e){const t=await this.tronWeb.fullNode.request("wallet/gettransactionbyid",{value:e},"post");if(!Object.keys(t).length)throw new Error("Transaction not found");return t}async getConfirmedTransaction(e){const t=await this.tronWeb.solidityNode.request("walletsolidity/gettransactionbyid",{value:e},"post");if(!Object.keys(t).length)throw new Error("Transaction not found");return t}getUnconfirmedTransactionInfo(e){return this.tronWeb.fullNode.request("wallet/gettransactioninfobyid",{value:e},"post")}getTransactionInfo(e){return this.tronWeb.solidityNode.request("walletsolidity/gettransactioninfobyid",{value:e},"post")}getTransactionsToAddress(e=this.tronWeb.defaultAddress.hex,t=30,r=0){return this.getTransactionsRelated(this.tronWeb.address.toHex(e),"to",t,r)}getTransactionsFromAddress(e=this.tronWeb.defaultAddress.hex,t=30,r=0){return this.getTransactionsRelated(this.tronWeb.address.toHex(e),"from",t,r)}async getTransactionsRelated(e=this.tronWeb.defaultAddress.hex,t="all",r=30,o=0){if(!["to","from","all"].includes(t))throw new Error('Invalid direction provided: Expected "to", "from" or "all"');if("all"==t){const[t,n]=await Promise.all([this.getTransactionsRelated(e,"from",r,o),this.getTransactionsRelated(e,"to",r,o)]);return[...t.map((e=>(e.direction="from",e))),...n.map((e=>(e.direction="to",e)))].sort(((e,t)=>t.raw_data.timestamp-e.raw_data.timestamp))}if(!this.tronWeb.isAddress(e))throw new Error("Invalid address provided");if(!s.default.isInteger(r)||r<0||o&&r<1)throw new Error("Invalid limit provided");if(!s.default.isInteger(o)||o<0)throw new Error("Invalid offset provided");return e=this.tronWeb.address.toHex(e),this.tronWeb.solidityNode.request(`walletextension/gettransactions${t}this`,{account:{address:e},offset:o,limit:r},"post").then((({transaction:e})=>e))}async getAccount(e=this.tronWeb.defaultAddress.hex){if(!this.tronWeb.isAddress(e))throw new Error("Invalid address provided");return e=this.tronWeb.address.toHex(e),this.tronWeb.solidityNode.request("walletsolidity/getaccount",{address:e},"post")}getAccountById(e){return this.getAccountInfoById(e,{confirmed:!0})}async getAccountInfoById(e,t){return this.validator.notValid([{name:"accountId",type:"hex",v