@onflow/transport-grpc
Advanced tools
Comparing version 0.0.3-alpha.1 to 0.0.3-multisig.0
@@ -0,1 +1,6 @@ | ||
### Unreleased | ||
- 2022-03-16 -- [@bthaile](https://github.com/bthaile) Payer can now be an array. | ||
- 2022-02-11 -- Uses Buffer as provided by context injection | ||
## 0.0.2 -- 2022-02-02 | ||
@@ -7,2 +12,2 @@ | ||
- 2022-01-13 -- [@JeffreyDoyle](https://github.com/JeffreyDoyle): Initial Implementation. | ||
- 2022-01-13 -- [@JeffreyDoyle](https://github.com/JeffreyDoyle): Initial Implementation. |
@@ -1,2 +0,2 @@ | ||
var e=require("@onflow/util-invariant"),t=require("@onflow/protobuf"),r=require("@improbable-eng/grpc-web"),n=require("@improbable-eng/grpc-web-node-http-transport"),o=require("@onflow/util-address"),s=function(t,n,o,s){try{return e.invariant(s.config,"SDK GRPC Unary Error: context.config must be defined."),Promise.resolve(s.config().get("grpc.metadata",{})).then(function(e){return new Promise(function(s,i){r.grpc.unary(n,{request:o,host:t,metadata:new r.grpc.Metadata(e),onEnd:function(e){var t=e.statusMessage;e.status===r.grpc.Code.OK?s(e.message):i(new Error(t))}})})})}catch(e){return Promise.reject(e)}};r.grpc.setDefaultTransport(n.NodeHttpTransport());var i=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e.invariant(n.node,"SDK Send Execute Script Error: opts.node must be defined."),e.invariant(r.response,"SDK Send Execute Script Error: context.response must be defined."),Promise.resolve(t).then(function(e){return t=e,Promise.resolve(t.block.id?u(t,r,n):t.block.height?c(t,r,n):a(t,r,n))})}catch(e){return Promise.reject(e)}},a=function(e,r,n){try{var o=n.unary||s,i=new t.ExecuteScriptAtLatestBlockRequest,a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return i.addArguments(d(e.arguments[t].asArgument))}),i.setScript(a),Promise.resolve(o(n.node,t.AccessAPI.ExecuteScriptAtLatestBlock,i,r)).then(function(t){return g(e,r,t)})}catch(e){return Promise.reject(e)}},c=function(e,r,n){try{var o=n.unary||s,i=new t.ExecuteScriptAtBlockHeightRequest;i.setBlockHeight(Number(e.block.height));var a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return i.addArguments(d(e.arguments[t].asArgument))}),i.setScript(a),Promise.resolve(o(n.node,t.AccessAPI.ExecuteScriptAtBlockHeight,i,r)).then(function(t){return g(e,r,t)})}catch(e){return Promise.reject(e)}},u=function(e,r,n){try{var o=n.unary||s,i=new t.ExecuteScriptAtBlockIDRequest;i.setBlockId(l(e.block.id));var a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return i.addArguments(d(e.arguments[t].asArgument))}),i.setScript(a),Promise.resolve(o(n.node,t.AccessAPI.ExecuteScriptAtBlockID,i,r)).then(function(t){return g(e,r,t)})}catch(e){return Promise.reject(e)}},d=function(e){return Buffer.from(JSON.stringify(e),"utf8")},l=function(e){return Buffer.from(e,"hex")};function g(e,t,r){var n=t.response();return n.tag=e.tag,n.encodedData=JSON.parse(Buffer.from(r.getValue_asU8()).toString("utf8")),n}function f(){return f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},f.apply(this,arguments)}var m=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e.invariant(n.node,"SDK Send Get Account Error: opts.node must be defined."),e.invariant(r.response,"SDK Get Account Error: context.response must be defined."),Promise.resolve(t).then(function(e){return t=e,Promise.resolve(null!==t.block.height?v(t,r,n):p(t,r,n))})}catch(e){return Promise.reject(e)}},p=function(e,r,n){try{var i=n.unary||s,a=new t.GetAccountAtLatestBlockRequest;return a.setAddress(h(o.sansPrefix(e.account.addr))),Promise.resolve(i(n.node,t.AccessAPI.GetAccountAtLatestBlock,a,r)).then(function(t){return I(e,r,t)})}catch(e){return Promise.reject(e)}},v=function(e,r,n){try{var i=n.unary||s,a=new t.GetAccountAtBlockHeightRequest;return a.setBlockHeight(Number(e.block.height)),a.setAddress(h(o.sansPrefix(e.account.addr))),Promise.resolve(i(n.node,t.AccessAPI.GetAccountAtBlockHeight,a,r)).then(function(t){return I(e,r,t)})}catch(e){return Promise.reject(e)}},S=function(e){return Buffer.from(e).toString("hex")},h=function(e){return Buffer.from(e.padStart(16,0),"hex")},B={1:"SHA2_256",2:"SHA2_384",3:"SHA3_256",4:"SHA3_384",5:"KMAC128_BLS_BLS12_381"},k={1:"ECDSA_P256",2:"ECDSA_secp256k1",3:"BLS_BLS12_381"};function I(e,t,r){var n=t.response();n.tag=e.tag;var s,i=r.getAccount(),a=(s=i.getContractsMap())?s.getEntryList().reduce(function(e,t){var r;return f({},e,((r={})[t[0]]=Buffer.from(t[1]||new UInt8Array).toString("utf8"),r))},{}):{};return n.account={address:o.withPrefix(S(i.getAddress_asU8())),balance:i.getBalance(),code:Buffer.from(i.getCode_asU8()||new UInt8Array).toString("utf8"),contracts:a,keys:i.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:S(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),signAlgoString:k[e.getSignAlgo()],hashAlgo:e.getHashAlgo(),hashAlgoString:B[e.getHashAlgo()],weight:e.getWeight(),sequenceNumber:e.getSequenceNumber(),revoked:e.getRevoked()}})},n}var y=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e.invariant(n.node,"SDK Send Get Block Header Error: opts.node must be defined."),e.invariant(r.response,"SDK Send Get Block Header Error: context.response must be defined."),Promise.resolve(t).then(function(e){var o=null!==(t=e).block.height;return Promise.resolve(null!==t.block.id?A(t,r,n):o?x(t,r,n):P(t,r,n))})}catch(e){return Promise.reject(e)}},P=function(e,r,n){try{var o,i=n.unary||s,a=new t.GetLatestBlockHeaderRequest;return null!=(o=e.block)&&o.isSealed&&a.setIsSealed(e.block.isSealed),Promise.resolve(i(n.node,t.AccessAPI.GetLatestBlockHeader,a,r)).then(function(t){return E(e,r,t)})}catch(e){return Promise.reject(e)}},x=function(e,r,n){try{var o=n.unary||s,i=new t.GetBlockHeaderByHeightRequest;return i.setHeight(Number(e.block.height)),Promise.resolve(o(n.node,t.AccessAPI.GetBlockHeaderByHeight,i,r)).then(function(t){return E(e,r,t)})}catch(e){return Promise.reject(e)}},A=function(e,r,n){try{var o=n.unary||s,i=new t.GetBlockHeaderByIDRequest;return i.setId(G(e.block.id)),Promise.resolve(o(n.node,t.AccessAPI.GetBlockHeaderByID,i,r)).then(function(t){return E(e,r,t)})}catch(e){return Promise.reject(e)}},b=function(e){return Buffer.from(e).toString("hex")},G=function(e){return Buffer.from(e,"hex")};function E(e,t,r){var n=r.getBlock(),o=t.response();return o.tag=e.tag,o.blockHeader={id:b(n.getId_asU8()),parentId:b(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp().toDate().toISOString()},o}var L=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e.invariant(n.node,"SDK Send Get Block Error: opts.node must be defined."),e.invariant(r.response,"SDK Send Get Block Error: context.response must be defined."),Promise.resolve(t).then(function(e){var o=null!==(t=e).block.height;return Promise.resolve(null!==t.block.id?T(t,r,n):o?w(t,r,n):D(t,r,n))})}catch(e){return Promise.reject(e)}},D=function(e,r,n){try{var o,i=n.unary||s,a=new t.GetLatestBlockRequest;return null!=(o=e.block)&&o.isSealed&&a.setIsSealed(e.block.isSealed),Promise.resolve(i(n.node,t.AccessAPI.GetLatestBlock,a,r)).then(function(t){return _(e,r,t)})}catch(e){return Promise.reject(e)}},w=function(e,r,n){try{var o=n.unary||s,i=new t.GetBlockByHeightRequest;return i.setHeight(Number(e.block.height)),Promise.resolve(o(n.node,t.AccessAPI.GetBlockByHeight,i,r)).then(function(t){return _(e,r,t)})}catch(e){return Promise.reject(e)}},T=function(e,r,n){try{var o=n.unary||s,i=new t.GetBlockByIDRequest;return i.setId(R(e.block.id)),Promise.resolve(o(n.node,t.AccessAPI.GetBlockByID,i,r)).then(function(t){return _(e,r,t)})}catch(e){return Promise.reject(e)}},H=function(e){return Buffer.from(e).toString("hex")},R=function(e){return Buffer.from(e,"hex")};function _(e,t,r){var n=r.getBlock(),o=n.getCollectionGuaranteesList(),s=n.getBlockSealsList(),i=n.getSignaturesList().map(H),a=t.response();return a.tag=e.tag,a.block={id:H(n.getId_asU8()),parentId:H(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp().toDate().toISOString(),collectionGuarantees:o.map(function(e){return{collectionId:H(e.getCollectionId_asU8()),signatures:e.getSignaturesList().map(H)}}),blockSeals:s.map(function(e){return{blockId:H(e.getBlockId_asU8()),executionReceiptId:H(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList().map(H),resultApprovalSignatures:e.getResultApprovalSignaturesList().map(H)}}),signatures:i},a}var U=function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e.invariant(o.node,"SDK Send Get Collection Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Get Collection Error: context.response must be defined.");var i=o.unary||s;return Promise.resolve(r).then(function(e){r=e;var s=new t.GetCollectionByIDRequest;return s.setId(j(r.collection.id)),Promise.resolve(i(o.node,t.AccessAPI.GetCollectionByID,s,n)).then(function(e){var t=e.getCollection(),o=n.response();return o.tag=r.tag,o.collection={id:K(t.getId_asU8()),transactionIds:t.getTransactionIdsList().map(K)},o})})}catch(e){return Promise.reject(e)}},K=function(e){return Buffer.from(e).toString("hex")},j=function(e){return Buffer.from(e,"hex")},q=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e.invariant(n.node,"SDK Send Get Events Error: opts.node must be defined."),e.invariant(r.response,"SDK Send Get Events Error: context.response must be defined."),Promise.resolve(t).then(function(o){var s=null!==(t=o).events.start,i=Array.isArray(t.events.blockIds)&&t.events.blockIds.length>0;return e.invariant(s||i,"SendGetEventsError: Unable to determine which get events request to send. Either a block height range, or block IDs must be specified."),Promise.resolve(s?C(t,r,n):N(t,r,n))})}catch(e){return Promise.reject(e)}},N=function(e,r,n){try{var o=n.unary||s,i=new t.GetEventsForBlockIDsRequest;return i.setType(e.events.eventType),e.events.blockIds.forEach(function(e){return i.addBlockIds(F(e))}),Promise.resolve(o(n.node,t.AccessAPI.GetEventsForBlockIDs,i,r)).then(function(t){return J(e,r,t)})}catch(e){return Promise.reject(e)}},C=function(e,r,n){try{var o=n.unary||s,i=new t.GetEventsForHeightRangeRequest;return i.setType(e.events.eventType),i.setStartHeight(Number(e.events.start)),i.setEndHeight(Number(e.events.end)),Promise.resolve(o(n.node,t.AccessAPI.GetEventsForHeightRange,i,r)).then(function(t){return J(e,r,t)})}catch(e){return Promise.reject(e)}},O=function(e){return Buffer.from(e).toString("hex")},F=function(e){return Buffer.from(e,"hex")};function J(e,t,r){var n=t.response();n.tag=e.tag;var o=r.getResultsList();return n.events=o.reduce(function(e,t){var r=O(t.getBlockId_asU8()),n=t.getBlockHeight(),o=t.getBlockTimestamp().toDate().toISOString();return t.getEventsList().forEach(function(t){e.push({blockId:r,blockHeight:n,blockTimestamp:o,type:t.getType(),transactionId:O(t.getTransactionId_asU8()),transactionIndex:t.getTransactionIndex(),eventIndex:t.getEventIndex(),payload:JSON.parse(Buffer.from(t.getPayload_asU8()).toString("utf8"))})}),e},[]),n}var M=function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e.invariant(o.node,"SDK Send Get Latest Block Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Get Latest Block Error: context.response must be defined."),Promise.resolve(r).then(function(e){r=e;var i=new t.GetLatestBlockRequest;return r.latestBlock&&r.latestBlock.isSealed&&(i.setIsSealed(r.latestBlock.isSealed),W()),r.block&&r.block.isSealed&&i.setIsSealed(r.block.isSealed),Promise.resolve(s(o.node,t.AccessAPI.GetLatestBlock,i,n)).then(function(e){var t=e.getBlock(),o=t.getCollectionGuaranteesList(),s=t.getBlockSealsList(),i=t.getSignaturesList(),a=n.response();return a.tag=r.tag,a.block={id:z(t.getId_asU8()),parentId:z(t.getParentId_asU8()),height:t.getHeight(),timestamp:t.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:z(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:z(e.getBlockId_asU8()),executionReceiptId:z(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}},z=function(e){return Buffer.from(e).toString("hex")},W=function(){console.error("\n %c@onflow/send Deprecation Notice\n ========================\n\n Operating upon data of the latestBlock field of the interaction object is deprecated and will no longer be recognized in future releases of @onflow/send.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/send/WARNINGS.md#0001-Deprecating-latestBlock-field\n\n =======================\n ".replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")},X=function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e.invariant(o.node,"SDK Send Get Transaction Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Get Transaction Error: context.response must be defined.");var i=o.unary||s;return Promise.resolve(r).then(function(e){r=e;var s=new t.GetTransactionRequest;return s.setId(Z(r.transaction.id)),Promise.resolve(i(o.node,t.AccessAPI.GetTransaction,s,n)).then(function(e){var t=n.response();t.tag=r.tag;var o,s=function(e){return{address:V(e.getAddress_asU8()),keyId:e.getKeyId(),signature:V(e.getSignature_asU8())}},i=e.getTransaction();return t.transaction={script:Buffer.from(i.getScript_asU8()).toString("utf8"),args:i.getArgumentsList().map(function(e){return JSON.parse(Buffer.from(e).toString("utf8"))}),referenceBlockId:V(i.getReferenceBlockId_asU8()),gasLimit:i.getGasLimit(),proposalKey:(o=i.getProposalKey(),{address:V(o.getAddress_asU8()),keyId:o.getKeyId(),sequenceNumber:o.getSequenceNumber()}),payer:V(i.getPayer_asU8()),authorizers:i.getAuthorizersList().map(V),payloadSignatures:i.getPayloadSignaturesList().map(s),envelopeSignatures:i.getEnvelopeSignaturesList().map(s)},t})})}catch(e){return Promise.reject(e)}},V=function(e){return Buffer.from(e).toString("hex")},Z=function(e){return Buffer.from(e,"hex")},Q=function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e.invariant(o.node,"SDK Send Get Transaction Status Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Get Transaction Status Error: context.response must be defined.");var i=o.unary||s;return Promise.resolve(r).then(function(e){r=e;var s=new t.GetTransactionRequest;return s.setId(ee(r.transaction.id)),Promise.resolve(i(o.node,t.AccessAPI.GetTransactionResult,s,n)).then(function(e){var t=e.getEventsList(),o=n.response();return o.tag=r.tag,o.transactionStatus={status:e.getStatus(),statusString:Y[e.getStatus()],statusCode:e.getStatusCode(),errorMessage:e.getErrorMessage(),events:t.map(function(e){return{type:e.getType(),transactionId:$(e.getTransactionId_asU8()),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:JSON.parse(Buffer.from(e.getPayload_asU8()).toString("utf8"))}})},o})})}catch(e){return Promise.reject(e)}},Y={0:"UNKNOWN",1:"PENDING",2:"FINALIZED",3:"EXECUTED",4:"SEALED",5:"EXPIRED"},$=function(e){return Buffer.from(e).toString("hex")},ee=function(e){return Buffer.from(e,"hex")},te=function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e.invariant(o.node,"SDK Send Ping Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Ping Error: context.response must be defined.");var i=o.unary||s;return Promise.resolve(r).then(function(e){r=e;var s=new t.PingRequest;return Promise.resolve(i(o.node,t.AccessAPI.Ping,s,n)).then(function(e){var t=n.response();return t.tag=r.tag,t})})}catch(e){return Promise.reject(e)}},re=function(r,n,i){void 0===n&&(n={}),void 0===i&&(i={});try{e.invariant(i.node,"SDK Send Transaction Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Transaction Error: context.response must be defined.");var a=i.unary||s;return Promise.resolve(r).then(function(e){r=e;var s=new t.Transaction;s.setScript(oe(r.message.cadence)),s.setGasLimit(r.message.computeLimit),s.setReferenceBlockId(r.message.refBlock?se(r.message.refBlock):null),s.setPayer(ie(o.sansPrefix(r.accounts[r.payer].addr))),r.message.arguments.forEach(function(e){return s.addArguments(ae(r.arguments[e].asArgument))}),r.authorizations.map(function(e){return r.accounts[e].addr}).reduce(function(e,t){return e.find(function(e){return e===t})?e:[].concat(e,[t])},[]).forEach(function(e){return s.addAuthorizers(ie(o.sansPrefix(e)))});var c=new t.Transaction.ProposalKey;c.setAddress(ie(o.sansPrefix(r.accounts[r.proposer].addr))),c.setKeyId(r.accounts[r.proposer].keyId),c.setSequenceNumber(r.accounts[r.proposer].sequenceNum),s.setProposalKey(c);for(var u=0,d=Object.values(r.accounts);u<d.length;u++){var l=d[u];try{if(!l.role.payer&&null!=l.signature){var g=new t.Transaction.Signature;g.setAddress(ie(o.sansPrefix(l.addr))),g.setKeyId(l.keyId),g.setSignature(se(l.signature)),s.addPayloadSignatures(g)}}catch(e){throw console.error("Trouble applying payload signature",{acct:l,ix:r}),e}}for(var f=0,m=Object.values(r.accounts);f<m.length;f++){var p=m[f];try{if(p.role.payer&&null!=p.signature){var v=new t.Transaction.Signature;v.setAddress(ie(o.sansPrefix(p.addr))),v.setKeyId(p.keyId),v.setSignature(se(p.signature)),s.addEnvelopeSignatures(v)}}catch(e){throw console.error("Trouble applying envelope signature",{acct:p,ix:r}),e}}var S=new t.SendTransactionRequest;S.setTransaction(s);var h=Date.now();return Promise.resolve(a(i.node,t.AccessAPI.SendTransaction,S,n)).then(function(e){var t=Date.now(),o=n.response();return o.tag=r.tag,o.transactionId=ne(e.getId_asU8()),"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("FLOW::TX",{detail:{txId:o.transactionId,delta:t-h}})),o})})}catch(e){return Promise.reject(e)}},ne=function(e){return Buffer.from(e).toString("hex")},oe=function(e){return Buffer.from(e,"utf8")},se=function(e){return Buffer.from(e,"hex")},ie=function(e){return Buffer.from(e.padStart(16,0),"hex")},ae=function(e){return Buffer.from(JSON.stringify(e),"utf8")},ce=function(e){return Buffer.from(e).toString("hex")},ue=function(e){return Buffer.from(e).toString("hex")};exports.send=function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e.invariant(o.node,'SDK Send Error: Either opts.node or "accessNode.api" in config must be defined.'),e.invariant(n.ix,"SDK Send Error: context.ix must be defined."),Promise.resolve(r).then(function(a){switch(r=a,!0){case n.ix.isTransaction(r):return o.sendTransaction?o.sendTransaction(r,n,o):re(r,n,o);case n.ix.isGetTransactionStatus(r):return o.sendGetTransactionStatus?o.sendGetTransactionStatus(r,n,o):Q(r,n,o);case n.ix.isGetTransaction(r):return o.sendGetTransaction?o.sendGetTransaction(r,n,o):X(r,n,o);case n.ix.isScript(r):return o.sendExecuteScript?o.sendExecuteScript(r,n,o):i(r,n,o);case n.ix.isGetAccount(r):return o.sendGetAccount?o.sendGetAccount(r,n,o):m(r,n,o);case n.ix.isGetEvents(r):return o.sendGetEvents?o.sendGetEvents(r,n,o):q(r,n,o);case n.ix.isGetLatestBlock(r):return o.sendGetLatestBlock?o.sendGetLatestBlock(r,n,o):M(r,n,o);case n.ix.isGetBlock(r):return o.sendGetBlock?o.sendGetBlock(r,n,o):L(r,n,o);case n.ix.isGetBlockHeader(r):return o.sendGetBlockHeader?o.sendGetBlockHeader(r,n,o):y(r,n,o);case n.ix.isGetBlockById(r):return o.sendGetBlockById?o.sendGetBlockById(r,n,o):function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e.invariant(o.node,"SDK Send Get Block By ID Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Get Block By ID Error: context.response must be defined."),Promise.resolve(r).then(function(e){r=e;var i=new t.GetBlockByIDRequest;return i.setId(Buffer.from(r.block.id,"hex")),Promise.resolve(s(o.node,t.AccessAPI.GetBlockByID,i,n)).then(function(e){var t=e.getBlock(),o=t.getCollectionGuaranteesList(),s=t.getBlockSealsList(),i=t.getSignaturesList(),a=n.response();return a.tag=r.tag,a.block={id:ce(t.getId_asU8()),parentId:ce(t.getParentId_asU8()),height:t.getHeight(),timestamp:t.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:ce(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:ce(e.getBlockId_asU8()),executionReceiptId:ce(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}}(r,n,o);case n.ix.isGetBlockByHeight(r):return o.sendGetBlockByHeight?o.sendGetBlockByHeight(r,n,o):function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e.invariant(o.node,"SDK Send Get Block By Height Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Get Block By Height Error: context.response must be defined."),Promise.resolve(r).then(function(e){r=e;var i=new t.GetBlockByHeightRequest;return i.setHeight(Number(r.block.height)),Promise.resolve(s(o.node,t.AccessAPI.GetBlockByHeight,i,n)).then(function(e){var t=e.getBlock(),o=t.getCollectionGuaranteesList(),s=t.getBlockSealsList(),i=t.getSignaturesList(),a=n.response();return a.tag=r.tag,a.block={id:ue(t.getId_asU8()),parentId:ue(t.getParentId_asU8()),height:t.getHeight(),timestamp:t.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:ue(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:ue(e.getBlockId_asU8()),executionReceiptId:ue(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}}(r,n,o);case n.ix.isGetCollection(r):return o.sendGetCollection?o.sendGetCollection(r,n,o):U(r,n,o);case n.ix.isPing(r):return o.sendPing?o.sendPing(r,n,o):te(r,n,o);default:return r}})}catch(e){return Promise.reject(e)}},exports.sendExecuteScript=i,exports.sendGetAccount=m,exports.sendGetBlock=L,exports.sendGetBlockHeader=y,exports.sendGetCollection=U,exports.sendGetEvents=q,exports.sendGetLatestBlock=M,exports.sendGetTransaction=X,exports.sendGetTransactionStatus=Q,exports.sendPing=te,exports.sendTransaction=re; | ||
var e=require("@onflow/util-invariant"),t=require("@onflow/protobuf"),r=require("@improbable-eng/grpc-web"),n=require("@improbable-eng/grpc-web-node-http-transport"),o=require("@onflow/util-address"),s=function(t,n,o,s){try{return e.invariant(s.config,"SDK GRPC Unary Error: context.config must be defined."),Promise.resolve(s.config().get("grpc.metadata",{})).then(function(e){return new Promise(function(s,i){r.grpc.unary(n,{request:o,host:t,metadata:new r.grpc.Metadata(e),onEnd:function(e){var t=e.statusMessage;e.status===r.grpc.Code.OK?s(e.message):i(new Error(t))}})})})}catch(e){return Promise.reject(e)}};r.grpc.setDefaultTransport(n.NodeHttpTransport());var i=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e.invariant(n.node,"SDK Send Execute Script Error: opts.node must be defined."),e.invariant(r.response,"SDK Send Execute Script Error: context.response must be defined."),e.invariant(r.Buffer,"SDK Send Execute Script Error: context.Buffer must be defined."),Promise.resolve(t).then(function(e){return t=e,Promise.resolve(t.block.id?u(t,r,n):t.block.height?c(t,r,n):a(t,r,n))})}catch(e){return Promise.reject(e)}},a=function(e,r,n){try{var o=n.unary||s,i=new t.ExecuteScriptAtLatestBlockRequest,a=r.Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return i.addArguments(d(e.arguments[t].asArgument,r))}),i.setScript(a),Promise.resolve(o(n.node,t.AccessAPI.ExecuteScriptAtLatestBlock,i,r)).then(function(t){return l(e,r,t)})}catch(e){return Promise.reject(e)}},c=function(e,r,n){try{var o=n.unary||s,i=new t.ExecuteScriptAtBlockHeightRequest;i.setBlockHeight(Number(e.block.height));var a=r.Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return i.addArguments(d(e.arguments[t].asArgument,r))}),i.setScript(a),Promise.resolve(o(n.node,t.AccessAPI.ExecuteScriptAtBlockHeight,i,r)).then(function(t){return l(e,r,t)})}catch(e){return Promise.reject(e)}},u=function(e,r,n){try{var o=n.unary||s,i=new t.ExecuteScriptAtBlockIDRequest;i.setBlockId(f(e.block.id,r));var a=r.Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return i.addArguments(d(e.arguments[t].asArgument,r))}),i.setScript(a),Promise.resolve(o(n.node,t.AccessAPI.ExecuteScriptAtBlockID,i,r)).then(function(t){return l(e,r,t)})}catch(e){return Promise.reject(e)}},d=function(e,t){return t.Buffer.from(JSON.stringify(e),"utf8")},f=function(e,t){return t.Buffer.from(e,"hex")};function l(e,t,r){var n=t.response();return n.tag=e.tag,n.encodedData=JSON.parse(t.Buffer.from(r.getValue_asU8()).toString("utf8")),n}function g(){return g=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},g.apply(this,arguments)}var m=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e.invariant(n.node,"SDK Send Get Account Error: opts.node must be defined."),e.invariant(r.response,"SDK Get Account Error: context.response must be defined."),e.invariant(r.Buffer,"SDK Get Account Error: context.Buffer must be defined."),Promise.resolve(t).then(function(e){return t=e,Promise.resolve(null!==t.block.height?v(t,r,n):p(t,r,n))})}catch(e){return Promise.reject(e)}},p=function(e,r,n){try{var i=n.unary||s,a=new t.GetAccountAtLatestBlockRequest;return a.setAddress(h(o.sansPrefix(e.account.addr),r)),Promise.resolve(i(n.node,t.AccessAPI.GetAccountAtLatestBlock,a,r)).then(function(t){return I(e,r,t)})}catch(e){return Promise.reject(e)}},v=function(e,r,n){try{var i=n.unary||s,a=new t.GetAccountAtBlockHeightRequest;return a.setBlockHeight(Number(e.block.height)),a.setAddress(h(o.sansPrefix(e.account.addr),r)),Promise.resolve(i(n.node,t.AccessAPI.GetAccountAtBlockHeight,a,r)).then(function(t){return I(e,r,t)})}catch(e){return Promise.reject(e)}},S=function(e,t){return t.Buffer.from(e).toString("hex")},h=function(e,t){return function(e,t,r){return r.Buffer.from(e.padStart(16,0),"hex")}(e,0,t)},B={1:"SHA2_256",2:"SHA2_384",3:"SHA3_256",4:"SHA3_384",5:"KMAC128_BLS_BLS12_381"},k={1:"ECDSA_P256",2:"ECDSA_secp256k1",3:"BLS_BLS12_381"};function I(e,t,r){var n=t.response();n.tag=e.tag;var s,i=r.getAccount(),a=(s=i.getContractsMap())?s.getEntryList().reduce(function(e,r){var n;return g({},e,((n={})[r[0]]=t.Buffer.from(r[1]||new UInt8Array).toString("utf8"),n))},{}):{};return n.account={address:o.withPrefix(S(i.getAddress_asU8(),t)),balance:i.getBalance(),code:t.Buffer.from(i.getCode_asU8()||new UInt8Array).toString("utf8"),contracts:a,keys:i.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:S(e.getPublicKey_asU8(),t),signAlgo:e.getSignAlgo(),signAlgoString:k[e.getSignAlgo()],hashAlgo:e.getHashAlgo(),hashAlgoString:B[e.getHashAlgo()],weight:e.getWeight(),sequenceNumber:e.getSequenceNumber(),revoked:e.getRevoked()}})},n}var y=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e.invariant(n.node,"SDK Send Get Block Header Error: opts.node must be defined."),e.invariant(r.response,"SDK Send Get Block Header Error: context.response must be defined."),e.invariant(r.Buffer,"SDK Send Get Block Header Error: context.Buffer must be defined."),Promise.resolve(t).then(function(e){var o=null!==(t=e).block.height;return Promise.resolve(null!==t.block.id?b(t,r,n):o?x(t,r,n):P(t,r,n))})}catch(e){return Promise.reject(e)}},P=function(e,r,n){try{var o,i=n.unary||s,a=new t.GetLatestBlockHeaderRequest;return null!=(o=e.block)&&o.isSealed&&a.setIsSealed(e.block.isSealed),Promise.resolve(i(n.node,t.AccessAPI.GetLatestBlockHeader,a,r)).then(function(t){return E(e,r,t)})}catch(e){return Promise.reject(e)}},x=function(e,r,n){try{var o=n.unary||s,i=new t.GetBlockHeaderByHeightRequest;return i.setHeight(Number(e.block.height)),Promise.resolve(o(n.node,t.AccessAPI.GetBlockHeaderByHeight,i,r)).then(function(t){return E(e,r,t)})}catch(e){return Promise.reject(e)}},b=function(e,r,n){try{var o=n.unary||s,i=new t.GetBlockHeaderByIDRequest;return i.setId(G(e.block.id,r)),Promise.resolve(o(n.node,t.AccessAPI.GetBlockHeaderByID,i,r)).then(function(t){return E(e,r,t)})}catch(e){return Promise.reject(e)}},A=function(e,t){return t.Buffer.from(e).toString("hex")},G=function(e,t){return t.Buffer.from(e,"hex")};function E(e,t,r){var n=r.getBlock(),o=t.response();return o.tag=e.tag,o.blockHeader={id:A(n.getId_asU8(),t),parentId:A(n.getParentId_asU8(),t),height:n.getHeight(),timestamp:n.getTimestamp().toDate().toISOString()},o}var D=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e.invariant(n.node,"SDK Send Get Block Error: opts.node must be defined."),e.invariant(r.response,"SDK Send Get Block Error: context.response must be defined."),e.invariant(r.Buffer,"SDK Send Get Block Error: context.Buffer must be defined."),Promise.resolve(t).then(function(e){var o=null!==(t=e).block.height;return Promise.resolve(null!==t.block.id?K(t,r,n):o?T(t,r,n):L(t,r,n))})}catch(e){return Promise.reject(e)}},L=function(e,r,n){try{var o,i=n.unary||s,a=new t.GetLatestBlockRequest;return null!=(o=e.block)&&o.isSealed&&a.setIsSealed(e.block.isSealed),Promise.resolve(i(n.node,t.AccessAPI.GetLatestBlock,a,r)).then(function(t){return R(e,r,t)})}catch(e){return Promise.reject(e)}},T=function(e,r,n){try{var o=n.unary||s,i=new t.GetBlockByHeightRequest;return i.setHeight(Number(e.block.height)),Promise.resolve(o(n.node,t.AccessAPI.GetBlockByHeight,i,r)).then(function(t){return R(e,r,t)})}catch(e){return Promise.reject(e)}},K=function(e,r,n){try{var o=n.unary||s,i=new t.GetBlockByIDRequest;return i.setId(H(e.block.id,r)),Promise.resolve(o(n.node,t.AccessAPI.GetBlockByID,i,r)).then(function(t){return R(e,r,t)})}catch(e){return Promise.reject(e)}},w=function(e,t){return t.Buffer.from(e).toString("hex")},H=function(e,t){return t.Buffer.from(e,"hex")};function R(e,t,r){var n=r.getBlock(),o=n.getCollectionGuaranteesList(),s=n.getBlockSealsList(),i=n.getSignaturesList().map(function(e){return w(e,t)}),a=t.response();return a.tag=e.tag,a.block={id:w(n.getId_asU8(),t),parentId:w(n.getParentId_asU8(),t),height:n.getHeight(),timestamp:n.getTimestamp().toDate().toISOString(),collectionGuarantees:o.map(function(e){return{collectionId:w(e.getCollectionId_asU8(),t),signatures:e.getSignaturesList().map(function(e){return w(e,t)})}}),blockSeals:s.map(function(e){return{blockId:w(e.getBlockId_asU8(),t),executionReceiptId:w(e.getExecutionReceiptId_asU8(),t),executionReceiptSignatures:e.getExecutionReceiptSignaturesList().map(function(e){return w(e,t)}),resultApprovalSignatures:e.getResultApprovalSignaturesList().map(function(e){return w(e,t)})}}),signatures:i},a}var _=function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e.invariant(o.node,"SDK Send Get Collection Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Get Collection Error: context.response must be defined."),e.invariant(n.Buffer,"SDK Send Get Collection Error: context.Buffer must be defined.");var i=o.unary||s;return Promise.resolve(r).then(function(e){r=e;var s=new t.GetCollectionByIDRequest;return s.setId(j(r.collection.id,n)),Promise.resolve(i(o.node,t.AccessAPI.GetCollectionByID,s,n)).then(function(e){var t=e.getCollection(),o=n.response();return o.tag=r.tag,o.collection={id:U(t.getId_asU8(),n),transactionIds:t.getTransactionIdsList().map(function(e){return U(e,n)})},o})})}catch(e){return Promise.reject(e)}},U=function(e,t){return t.Buffer.from(e).toString("hex")},j=function(e,t){return t.Buffer.from(e,"hex")},q=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e.invariant(n.node,"SDK Send Get Events Error: opts.node must be defined."),e.invariant(r.response,"SDK Send Get Events Error: context.response must be defined."),e.invariant(r.Buffer,"SDK Send Get Events Error: context.Buffer must be defined."),Promise.resolve(t).then(function(o){var s=null!==(t=o).events.start,i=Array.isArray(t.events.blockIds)&&t.events.blockIds.length>0;return e.invariant(s||i,"SendGetEventsError: Unable to determine which get events request to send. Either a block height range, or block IDs must be specified."),Promise.resolve(s?C(t,r,n):N(t,r,n))})}catch(e){return Promise.reject(e)}},N=function(e,r,n){try{var o=n.unary||s,i=new t.GetEventsForBlockIDsRequest;return i.setType(e.events.eventType),e.events.blockIds.forEach(function(e){return i.addBlockIds(F(e,r))}),Promise.resolve(o(n.node,t.AccessAPI.GetEventsForBlockIDs,i,r)).then(function(t){return J(e,r,t)})}catch(e){return Promise.reject(e)}},C=function(e,r,n){try{var o=n.unary||s,i=new t.GetEventsForHeightRangeRequest;return i.setType(e.events.eventType),i.setStartHeight(Number(e.events.start)),i.setEndHeight(Number(e.events.end)),Promise.resolve(o(n.node,t.AccessAPI.GetEventsForHeightRange,i,r)).then(function(t){return J(e,r,t)})}catch(e){return Promise.reject(e)}},O=function(e,t){return t.Buffer.from(e).toString("hex")},F=function(e,t){return t.Buffer.from(e,"hex")};function J(e,t,r){var n=t.response();n.tag=e.tag;var o=r.getResultsList();return n.events=o.reduce(function(e,r){var n=O(r.getBlockId_asU8(),t),o=r.getBlockHeight(),s=r.getBlockTimestamp().toDate().toISOString();return r.getEventsList().forEach(function(r){e.push({blockId:n,blockHeight:o,blockTimestamp:s,type:r.getType(),transactionId:O(r.getTransactionId_asU8(),t),transactionIndex:r.getTransactionIndex(),eventIndex:r.getEventIndex(),payload:JSON.parse(t.Buffer.from(r.getPayload_asU8()).toString("utf8"))})}),e},[]),n}var M=function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e.invariant(o.node,"SDK Send Get Latest Block Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Get Latest Block Error: context.response must be defined."),e.invariant(n.Buffer,"SDK Send Get Latest Block Error: context.Buffer must be defined."),Promise.resolve(r).then(function(e){r=e;var i=new t.GetLatestBlockRequest;return r.latestBlock&&r.latestBlock.isSealed&&(i.setIsSealed(r.latestBlock.isSealed),W()),r.block&&r.block.isSealed&&i.setIsSealed(r.block.isSealed),Promise.resolve(s(o.node,t.AccessAPI.GetLatestBlock,i,n)).then(function(e){var t=e.getBlock(),o=t.getCollectionGuaranteesList(),s=t.getBlockSealsList(),i=t.getSignaturesList(),a=n.response();return a.tag=r.tag,a.block={id:z(t.getId_asU8(),n),parentId:z(t.getParentId_asU8(),n),height:t.getHeight(),timestamp:t.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:z(e.getCollectionId_asU8(),n),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:z(e.getBlockId_asU8(),n),executionReceiptId:z(e.getExecutionReceiptId_asU8(),n),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}},z=function(e,t){return t.Buffer.from(e).toString("hex")},W=function(){console.error("\n %c@onflow/send Deprecation Notice\n ========================\n\n Operating upon data of the latestBlock field of the interaction object is deprecated and will no longer be recognized in future releases of @onflow/send.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/send/WARNINGS.md#0001-Deprecating-latestBlock-field\n\n =======================\n ".replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")},X=function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e.invariant(o.node,"SDK Send Get Transaction Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Get Transaction Error: context.response must be defined."),e.invariant(n.Buffer,"SDK Send Get Transaction Error: context.Buffer must be defined.");var i=o.unary||s;return Promise.resolve(r).then(function(e){r=e;var s=new t.GetTransactionRequest;return s.setId(Z(r.transaction.id,n)),Promise.resolve(i(o.node,t.AccessAPI.GetTransaction,s,n)).then(function(e){var t=n.response();t.tag=r.tag;var o,s=function(e){return{address:V(e.getAddress_asU8(),n),keyId:e.getKeyId(),signature:V(e.getSignature_asU8(),n)}},i=e.getTransaction();return t.transaction={script:n.Buffer.from(i.getScript_asU8()).toString("utf8"),args:i.getArgumentsList().map(function(e){return JSON.parse(n.Buffer.from(e).toString("utf8"))}),referenceBlockId:V(i.getReferenceBlockId_asU8(),n),gasLimit:i.getGasLimit(),proposalKey:(o=i.getProposalKey(),{address:V(o.getAddress_asU8(),n),keyId:o.getKeyId(),sequenceNumber:o.getSequenceNumber()}),payer:V(i.getPayer_asU8(),n),authorizers:i.getAuthorizersList().map(function(e){return V(e,n)}),payloadSignatures:i.getPayloadSignaturesList().map(s),envelopeSignatures:i.getEnvelopeSignaturesList().map(s)},t})})}catch(e){return Promise.reject(e)}},V=function(e,t){return t.Buffer.from(e).toString("hex")},Z=function(e,t){return t.Buffer.from(e,"hex")},Q=function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e.invariant(o.node,"SDK Send Get Transaction Status Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Get Transaction Status Error: context.response must be defined."),e.invariant(n.Buffer,"SDK Send Get Transaction Status Error: context.Buffer must be defined.");var i=o.unary||s;return Promise.resolve(r).then(function(e){r=e;var s=new t.GetTransactionRequest;return s.setId(ee(r.transaction.id,n)),Promise.resolve(i(o.node,t.AccessAPI.GetTransactionResult,s,n)).then(function(e){var t=e.getEventsList(),o=n.response();return o.tag=r.tag,o.transactionStatus={status:e.getStatus(),statusString:Y[e.getStatus()],statusCode:e.getStatusCode(),errorMessage:e.getErrorMessage(),events:t.map(function(e){return{type:e.getType(),transactionId:$(e.getTransactionId_asU8(),n),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:JSON.parse(n.Buffer.from(e.getPayload_asU8()).toString("utf8"))}})},o})})}catch(e){return Promise.reject(e)}},Y={0:"UNKNOWN",1:"PENDING",2:"FINALIZED",3:"EXECUTED",4:"SEALED",5:"EXPIRED"},$=function(e,t){return t.Buffer.from(e).toString("hex")},ee=function(e,t){return t.Buffer.from(e,"hex")},te=function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e.invariant(o.node,"SDK Send Ping Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Ping Error: context.response must be defined.");var i=o.unary||s;return Promise.resolve(r).then(function(e){r=e;var s=new t.PingRequest;return Promise.resolve(i(o.node,t.AccessAPI.Ping,s,n)).then(function(e){var t=n.response();return t.tag=r.tag,t})})}catch(e){return Promise.reject(e)}},re=function(r,n,i){void 0===n&&(n={}),void 0===i&&(i={});try{e.invariant(i.node,"SDK Send Transaction Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Transaction Error: context.response must be defined."),e.invariant(n.Buffer,"SDK Send Transaction Error: context.Buffer must be defined.");var a=i.unary||s;return Promise.resolve(r).then(function(e){r=e;var s=new t.Transaction;s.setScript(oe(r.message.cadence,n)),s.setGasLimit(r.message.computeLimit),s.setReferenceBlockId(r.message.refBlock?se(r.message.refBlock,n):null),s.setPayer(ie(o.sansPrefix(r.accounts[Array.isArray(r.payer)?r.payer[0]:r.payer].addr),n)),r.message.arguments.forEach(function(e){return s.addArguments(ae(r.arguments[e].asArgument,n))}),r.authorizations.map(function(e){return r.accounts[e].addr}).reduce(function(e,t){return e.find(function(e){return e===t})?e:[].concat(e,[t])},[]).forEach(function(e){return s.addAuthorizers(ie(o.sansPrefix(e),n))});var c=new t.Transaction.ProposalKey;c.setAddress(ie(o.sansPrefix(r.accounts[r.proposer].addr),n)),c.setKeyId(r.accounts[r.proposer].keyId),c.setSequenceNumber(r.accounts[r.proposer].sequenceNum),s.setProposalKey(c);for(var u=0,d=Object.values(r.accounts);u<d.length;u++){var f=d[u];try{if(!f.role.payer&&null!=f.signature){var l=new t.Transaction.Signature;l.setAddress(ie(o.sansPrefix(f.addr),n)),l.setKeyId(f.keyId),l.setSignature(se(f.signature,n)),s.addPayloadSignatures(l)}}catch(e){throw console.error("Trouble applying payload signature",{acct:f,ix:r}),e}}for(var g=0,m=Object.values(r.accounts);g<m.length;g++){var p=m[g];try{if(p.role.payer&&null!=p.signature){var v=new t.Transaction.Signature;v.setAddress(ie(o.sansPrefix(p.addr),n)),v.setKeyId(p.keyId),v.setSignature(se(p.signature,n)),s.addEnvelopeSignatures(v)}}catch(e){throw console.error("Trouble applying envelope signature",{acct:p,ix:r}),e}}var S=new t.SendTransactionRequest;S.setTransaction(s);var h=Date.now();return Promise.resolve(a(i.node,t.AccessAPI.SendTransaction,S,n)).then(function(e){var t=Date.now(),o=n.response();return o.tag=r.tag,o.transactionId=ne(e.getId_asU8(),n),"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("FLOW::TX",{detail:{txId:o.transactionId,delta:t-h}})),o})})}catch(e){return Promise.reject(e)}},ne=function(e,t){return t.Buffer.from(e).toString("hex")},oe=function(e,t){return t.Buffer.from(e,"utf8")},se=function(e,t){return t.Buffer.from(e,"hex")},ie=function(e,t){return function(e,t,r){return r.Buffer.from(e.padStart(16,0),"hex")}(e,0,t)},ae=function(e,t){return t.Buffer.from(JSON.stringify(e),"utf8")},ce=function(e,t){return t.Buffer.from(e).toString("hex")},ue=function(e,t){return t.Buffer.from(e).toString("hex")};exports.send=function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e.invariant(o.node,'SDK Send Error: Either opts.node or "accessNode.api" in config must be defined.'),e.invariant(n.ix,"SDK Send Error: context.ix must be defined."),Promise.resolve(r).then(function(a){switch(r=a,!0){case n.ix.isTransaction(r):return o.sendTransaction?o.sendTransaction(r,n,o):re(r,n,o);case n.ix.isGetTransactionStatus(r):return o.sendGetTransactionStatus?o.sendGetTransactionStatus(r,n,o):Q(r,n,o);case n.ix.isGetTransaction(r):return o.sendGetTransaction?o.sendGetTransaction(r,n,o):X(r,n,o);case n.ix.isScript(r):return o.sendExecuteScript?o.sendExecuteScript(r,n,o):i(r,n,o);case n.ix.isGetAccount(r):return o.sendGetAccount?o.sendGetAccount(r,n,o):m(r,n,o);case n.ix.isGetEvents(r):return o.sendGetEvents?o.sendGetEvents(r,n,o):q(r,n,o);case n.ix.isGetLatestBlock(r):return o.sendGetLatestBlock?o.sendGetLatestBlock(r,n,o):M(r,n,o);case n.ix.isGetBlock(r):return o.sendGetBlock?o.sendGetBlock(r,n,o):D(r,n,o);case n.ix.isGetBlockHeader(r):return o.sendGetBlockHeader?o.sendGetBlockHeader(r,n,o):y(r,n,o);case n.ix.isGetBlockById(r):return o.sendGetBlockById?o.sendGetBlockById(r,n,o):function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e.invariant(o.node,"SDK Send Get Block By ID Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Get Block By ID Error: context.response must be defined."),e.invariant(n.Buffer,"SDK Send Get Block By ID Error: context.Buffer must be defined."),Promise.resolve(r).then(function(e){r=e;var i=new t.GetBlockByIDRequest;return i.setId(function(e,t){return t.Buffer.from(e,"hex")}(r.block.id,n)),Promise.resolve(s(o.node,t.AccessAPI.GetBlockByID,i,n)).then(function(e){var t=e.getBlock(),o=t.getCollectionGuaranteesList(),s=t.getBlockSealsList(),i=t.getSignaturesList(),a=n.response();return a.tag=r.tag,a.block={id:ce(t.getId_asU8(),n),parentId:ce(t.getParentId_asU8(),n),height:t.getHeight(),timestamp:t.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:ce(e.getCollectionId_asU8(),n),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:ce(e.getBlockId_asU8(),n),executionReceiptId:ce(e.getExecutionReceiptId_asU8(),n),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}}(r,n,o);case n.ix.isGetBlockByHeight(r):return o.sendGetBlockByHeight?o.sendGetBlockByHeight(r,n,o):function(r,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e.invariant(o.node,"SDK Send Get Block By Height Error: opts.node must be defined."),e.invariant(n.response,"SDK Send Get Block By Height Error: context.response must be defined."),e.invariant(n.Buffer,"SDK Send Get Block By Height Error: context.Buffer must be defined."),Promise.resolve(r).then(function(e){r=e;var i=new t.GetBlockByHeightRequest;return i.setHeight(Number(r.block.height)),Promise.resolve(s(o.node,t.AccessAPI.GetBlockByHeight,i,n)).then(function(e){var t=e.getBlock(),o=t.getCollectionGuaranteesList(),s=t.getBlockSealsList(),i=t.getSignaturesList(),a=n.response();return a.tag=r.tag,a.block={id:ue(t.getId_asU8(),n),parentId:ue(t.getParentId_asU8(),n),height:t.getHeight(),timestamp:t.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:ue(e.getCollectionId_asU8(),n),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:ue(e.getBlockId_asU8(),n),executionReceiptId:ue(e.getExecutionReceiptId_asU8(),n),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}}(r,n,o);case n.ix.isGetCollection(r):return o.sendGetCollection?o.sendGetCollection(r,n,o):_(r,n,o);case n.ix.isPing(r):return o.sendPing?o.sendPing(r,n,o):te(r,n,o);default:return r}})}catch(e){return Promise.reject(e)}},exports.sendExecuteScript=i,exports.sendGetAccount=m,exports.sendGetBlock=D,exports.sendGetBlockHeader=y,exports.sendGetCollection=_,exports.sendGetEvents=q,exports.sendGetLatestBlock=M,exports.sendGetTransaction=X,exports.sendGetTransactionStatus=Q,exports.sendPing=te,exports.sendTransaction=re; | ||
//# sourceMappingURL=sdk-send-grpc.js.map |
@@ -1,2 +0,2 @@ | ||
import{invariant as e}from"@onflow/util-invariant";import{ExecuteScriptAtBlockIDRequest as t,AccessAPI as n,ExecuteScriptAtBlockHeightRequest as s,ExecuteScriptAtLatestBlockRequest as o,GetAccountAtBlockHeightRequest as r,GetAccountAtLatestBlockRequest as a,GetBlockHeaderByIDRequest as i,GetBlockHeaderByHeightRequest as c,GetLatestBlockHeaderRequest as d,GetBlockByIDRequest as u,GetBlockByHeightRequest as g,GetLatestBlockRequest as l,GetCollectionByIDRequest as f,GetEventsForHeightRangeRequest as p,GetEventsForBlockIDsRequest as S,GetTransactionRequest as m,PingRequest as B,Transaction as k,SendTransactionRequest as y}from"@onflow/protobuf";import{grpc as h}from"@improbable-eng/grpc-web";import{NodeHttpTransport as I}from"@improbable-eng/grpc-web-node-http-transport";import{sansPrefix as b,withPrefix as w}from"@onflow/util-address";async function x(t,n,s,o){e(o.config,"SDK GRPC Unary Error: context.config must be defined.");const r=await o.config().get("grpc.metadata",{});return new Promise((e,o)=>{h.unary(n,{request:s,host:t,metadata:new h.Metadata(r),onEnd:({status:t,statusMessage:n,message:s})=>{t===h.Code.OK?e(s):o(new Error(n))}})})}h.setDefaultTransport(I());const E=e=>Buffer.from(JSON.stringify(e),"utf8");function G(e,t,n){let s=t.response();return s.tag=e.tag,s.encodedData=JSON.parse(Buffer.from(n.getValue_asU8()).toString("utf8")),s}async function A(r,a={},i={}){return e(i.node,"SDK Send Execute Script Error: opts.node must be defined."),e(a.response,"SDK Send Execute Script Error: context.response must be defined."),(r=await r).block.id?await async function(e,s,o){const r=o.unary||x,a=new t;a.setBlockId(Buffer.from(e.block.id,"hex"));const i=Buffer.from(e.message.cadence,"utf8");e.message.arguments.forEach(t=>a.addArguments(E(e.arguments[t].asArgument))),a.setScript(i);const c=await r(o.node,n.ExecuteScriptAtBlockID,a,s);return G(e,s,c)}(r,a,i):r.block.height?await async function(e,t,o){const r=o.unary||x,a=new s;a.setBlockHeight(Number(e.block.height));const i=Buffer.from(e.message.cadence,"utf8");e.message.arguments.forEach(t=>a.addArguments(E(e.arguments[t].asArgument))),a.setScript(i);const c=await r(o.node,n.ExecuteScriptAtBlockHeight,a,t);return G(e,t,c)}(r,a,i):await async function(e,t,s){const r=s.unary||x,a=new o,i=Buffer.from(e.message.cadence,"utf8");e.message.arguments.forEach(t=>a.addArguments(E(e.arguments[t].asArgument))),a.setScript(i);const c=await r(s.node,n.ExecuteScriptAtLatestBlock,a,t);return G(e,t,c)}(r,a,i)}function v(){return v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},v.apply(this,arguments)}const L=e=>Buffer.from(e).toString("hex"),D=e=>Buffer.from(e.padStart(16,0),"hex"),_={1:"SHA2_256",2:"SHA2_384",3:"SHA3_256",4:"SHA3_384",5:"KMAC128_BLS_BLS12_381"},U={1:"ECDSA_P256",2:"ECDSA_secp256k1",3:"BLS_BLS12_381"};function K(e,t,n){let s=t.response();s.tag=e.tag;const o=n.getAccount();let r;const a=(r=o.getContractsMap())?r.getEntryList().reduce((e,t)=>v({},e,{[t[0]]:Buffer.from(t[1]||new UInt8Array).toString("utf8")}),{}):{};return s.account={address:w(L(o.getAddress_asU8())),balance:o.getBalance(),code:Buffer.from(o.getCode_asU8()||new UInt8Array).toString("utf8"),contracts:a,keys:o.getKeysList().map(e=>({index:e.getIndex(),publicKey:L(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),signAlgoString:U[e.getSignAlgo()],hashAlgo:e.getHashAlgo(),hashAlgoString:_[e.getHashAlgo()],weight:e.getWeight(),sequenceNumber:e.getSequenceNumber(),revoked:e.getRevoked()}))},s}async function T(t,s={},o={}){return e(o.node,"SDK Send Get Account Error: opts.node must be defined."),e(s.response,"SDK Get Account Error: context.response must be defined."),null!==(t=await t).block.height?await async function(e,t,s){const o=s.unary||x,a=new r;return a.setBlockHeight(Number(e.block.height)),a.setAddress(D(b(e.account.addr))),K(e,t,await o(s.node,n.GetAccountAtBlockHeight,a,t))}(t,s,o):await async function(e,t,s){const o=s.unary||x,r=new a;return r.setAddress(D(b(e.account.addr))),K(e,t,await o(s.node,n.GetAccountAtLatestBlock,r,t))}(t,s,o)}const H=e=>Buffer.from(e).toString("hex");function N(e,t,n){const s=n.getBlock(),o=t.response();return o.tag=e.tag,o.blockHeader={id:H(s.getId_asU8()),parentId:H(s.getParentId_asU8()),height:s.getHeight(),timestamp:s.getTimestamp().toDate().toISOString()},o}async function R(t,s={},o={}){e(o.node,"SDK Send Get Block Header Error: opts.node must be defined."),e(s.response,"SDK Send Get Block Header Error: context.response must be defined.");const r=null!==(t=await t).block.height;return null!==t.block.id?await async function(e,t,s){const o=s.unary||x,r=new i;return r.setId(Buffer.from(e.block.id,"hex")),N(e,t,await o(s.node,n.GetBlockHeaderByID,r,t))}(t,s,o):r?await async function(e,t,s){const o=s.unary||x,r=new c;return r.setHeight(Number(e.block.height)),N(e,t,await o(s.node,n.GetBlockHeaderByHeight,r,t))}(t,s,o):await async function(e,t,s){var o;const r=s.unary||x,a=new d;return null!=(o=e.block)&&o.isSealed&&a.setIsSealed(e.block.isSealed),N(e,t,await r(s.node,n.GetLatestBlockHeader,a,t))}(t,s,o)}const P=e=>Buffer.from(e).toString("hex");function C(e,t,n){const s=n.getBlock(),o=s.getCollectionGuaranteesList(),r=s.getBlockSealsList(),a=s.getSignaturesList().map(P),i=t.response();return i.tag=e.tag,i.block={id:P(s.getId_asU8()),parentId:P(s.getParentId_asU8()),height:s.getHeight(),timestamp:s.getTimestamp().toDate().toISOString(),collectionGuarantees:o.map(e=>({collectionId:P(e.getCollectionId_asU8()),signatures:e.getSignaturesList().map(P)})),blockSeals:r.map(e=>({blockId:P(e.getBlockId_asU8()),executionReceiptId:P(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList().map(P),resultApprovalSignatures:e.getResultApprovalSignaturesList().map(P)})),signatures:a},i}async function O(t,s={},o={}){e(o.node,"SDK Send Get Block Error: opts.node must be defined."),e(s.response,"SDK Send Get Block Error: context.response must be defined.");const r=null!==(t=await t).block.height;return null!==t.block.id?await async function(e,t,s){const o=s.unary||x,r=new u;return r.setId(Buffer.from(e.block.id,"hex")),C(e,t,await o(s.node,n.GetBlockByID,r,t))}(t,s,o):r?await async function(e,t,s){const o=s.unary||x,r=new g;return r.setHeight(Number(e.block.height)),C(e,t,await o(s.node,n.GetBlockByHeight,r,t))}(t,s,o):await async function(e,t,s){var o;const r=s.unary||x,a=new l;return null!=(o=e.block)&&o.isSealed&&a.setIsSealed(e.block.isSealed),C(e,t,await r(s.node,n.GetLatestBlock,a,t))}(t,s,o)}const q=e=>Buffer.from(e).toString("hex");async function j(t,s={},o={}){e(o.node,"SDK Send Get Collection Error: opts.node must be defined."),e(s.response,"SDK Send Get Collection Error: context.response must be defined.");const r=o.unary||x;t=await t;const a=new f;a.setId(Buffer.from(t.collection.id,"hex"));const i=(await r(o.node,n.GetCollectionByID,a,s)).getCollection(),c=s.response();return c.tag=t.tag,c.collection={id:q(i.getId_asU8()),transactionIds:i.getTransactionIdsList().map(q)},c}const J=e=>Buffer.from(e).toString("hex");function M(e,t,n){let s=t.response();s.tag=e.tag;const o=n.getResultsList();return s.events=o.reduce((e,t)=>{const n=J(t.getBlockId_asU8()),s=t.getBlockHeight(),o=t.getBlockTimestamp().toDate().toISOString();return t.getEventsList().forEach(t=>{e.push({blockId:n,blockHeight:s,blockTimestamp:o,type:t.getType(),transactionId:J(t.getTransactionId_asU8()),transactionIndex:t.getTransactionIndex(),eventIndex:t.getEventIndex(),payload:JSON.parse(Buffer.from(t.getPayload_asU8()).toString("utf8"))})}),e},[]),s}async function z(t,s={},o={}){e(o.node,"SDK Send Get Events Error: opts.node must be defined."),e(s.response,"SDK Send Get Events Error: context.response must be defined.");const r=null!==(t=await t).events.start,a=Array.isArray(t.events.blockIds)&&t.events.blockIds.length>0;return e(r||a,"SendGetEventsError: Unable to determine which get events request to send. Either a block height range, or block IDs must be specified."),r?await async function(e,t,s){const o=s.unary||x,r=new p;return r.setType(e.events.eventType),r.setStartHeight(Number(e.events.start)),r.setEndHeight(Number(e.events.end)),M(e,t,await o(s.node,n.GetEventsForHeightRange,r,t))}(t,s,o):await async function(e,t,s){const o=s.unary||x,r=new S;return r.setType(e.events.eventType),e.events.blockIds.forEach(e=>r.addBlockIds(Buffer.from(e,"hex"))),M(e,t,await o(s.node,n.GetEventsForBlockIDs,r,t))}(t,s,o)}const F=e=>Buffer.from(e).toString("hex");async function W(t,s={},o={}){e(o.node,"SDK Send Get Latest Block Error: opts.node must be defined."),e(s.response,"SDK Send Get Latest Block Error: context.response must be defined."),t=await t;const r=new l;t.latestBlock&&t.latestBlock.isSealed&&(r.setIsSealed(t.latestBlock.isSealed),console.error("\n %c@onflow/send Deprecation Notice\n ========================\n\n Operating upon data of the latestBlock field of the interaction object is deprecated and will no longer be recognized in future releases of @onflow/send.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/send/WARNINGS.md#0001-Deprecating-latestBlock-field\n\n =======================\n ".replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")),t.block&&t.block.isSealed&&r.setIsSealed(t.block.isSealed);const a=(await x(o.node,n.GetLatestBlock,r,s)).getBlock(),i=a.getCollectionGuaranteesList(),c=a.getBlockSealsList(),d=a.getSignaturesList(),u=s.response();return u.tag=t.tag,u.block={id:F(a.getId_asU8()),parentId:F(a.getParentId_asU8()),height:a.getHeight(),timestamp:a.getTimestamp(),collectionGuarantees:i.map(e=>({collectionId:F(e.getCollectionId_asU8()),signatures:e.getSignaturesList()})),blockSeals:c.map(e=>({blockId:F(e.getBlockId_asU8()),executionReceiptId:F(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:d},u}const X=e=>Buffer.from(e).toString("hex");async function V(t,s={},o={}){e(o.node,"SDK Send Get Transaction Error: opts.node must be defined."),e(s.response,"SDK Send Get Transaction Error: context.response must be defined.");const r=o.unary||x;t=await t;const a=new m;a.setId(Buffer.from(t.transaction.id,"hex"));const i=await r(o.node,n.GetTransaction,a,s);let c=s.response();c.tag=t.tag;const d=e=>({address:X(e.getAddress_asU8()),keyId:e.getKeyId(),signature:X(e.getSignature_asU8())});let u=i.getTransaction();var g;return c.transaction={script:Buffer.from(u.getScript_asU8()).toString("utf8"),args:u.getArgumentsList().map(e=>JSON.parse(Buffer.from(e).toString("utf8"))),referenceBlockId:X(u.getReferenceBlockId_asU8()),gasLimit:u.getGasLimit(),proposalKey:(g=u.getProposalKey(),{address:X(g.getAddress_asU8()),keyId:g.getKeyId(),sequenceNumber:g.getSequenceNumber()}),payer:X(u.getPayer_asU8()),authorizers:u.getAuthorizersList().map(X),payloadSignatures:u.getPayloadSignaturesList().map(d),envelopeSignatures:u.getEnvelopeSignaturesList().map(d)},c}const Z={0:"UNKNOWN",1:"PENDING",2:"FINALIZED",3:"EXECUTED",4:"SEALED",5:"EXPIRED"};async function Q(t,s={},o={}){e(o.node,"SDK Send Get Transaction Status Error: opts.node must be defined."),e(s.response,"SDK Send Get Transaction Status Error: context.response must be defined.");const r=o.unary||x;t=await t;const a=new m;a.setId(Buffer.from(t.transaction.id,"hex"));const i=await r(o.node,n.GetTransactionResult,a,s);let c=i.getEventsList(),d=s.response();return d.tag=t.tag,d.transactionStatus={status:i.getStatus(),statusString:Z[i.getStatus()],statusCode:i.getStatusCode(),errorMessage:i.getErrorMessage(),events:c.map(e=>{return{type:e.getType(),transactionId:(t=e.getTransactionId_asU8(),Buffer.from(t).toString("hex")),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:JSON.parse(Buffer.from(e.getPayload_asU8()).toString("utf8"))};var t})},d}async function Y(t,s={},o={}){e(o.node,"SDK Send Ping Error: opts.node must be defined."),e(s.response,"SDK Send Ping Error: context.response must be defined.");const r=o.unary||x;t=await t;const a=new B;await r(o.node,n.Ping,a,s);let i=s.response();return i.tag=t.tag,i}const $=e=>Buffer.from(e,"hex"),ee=e=>Buffer.from(e.padStart(16,0),"hex");async function te(t,s={},o={}){e(o.node,"SDK Send Transaction Error: opts.node must be defined."),e(s.response,"SDK Send Transaction Error: context.response must be defined.");const r=o.unary||x;t=await t;const a=new k;a.setScript(Buffer.from(t.message.cadence,"utf8")),a.setGasLimit(t.message.computeLimit),a.setReferenceBlockId(t.message.refBlock?$(t.message.refBlock):null),a.setPayer(ee(b(t.accounts[t.payer].addr))),t.message.arguments.forEach(e=>a.addArguments((e=>Buffer.from(JSON.stringify(e),"utf8"))(t.arguments[e].asArgument))),t.authorizations.map(e=>t.accounts[e].addr).reduce((e,t)=>e.find(e=>e===t)?e:[...e,t],[]).forEach(e=>a.addAuthorizers(ee(b(e))));const i=new k.ProposalKey;i.setAddress(ee(b(t.accounts[t.proposer].addr))),i.setKeyId(t.accounts[t.proposer].keyId),i.setSequenceNumber(t.accounts[t.proposer].sequenceNum),a.setProposalKey(i);for(let e of Object.values(t.accounts))try{if(!e.role.payer&&null!=e.signature){const t=new k.Signature;t.setAddress(ee(b(e.addr))),t.setKeyId(e.keyId),t.setSignature($(e.signature)),a.addPayloadSignatures(t)}}catch(n){throw console.error("Trouble applying payload signature",{acct:e,ix:t}),n}for(let e of Object.values(t.accounts))try{if(e.role.payer&&null!=e.signature){const t=new k.Signature;t.setAddress(ee(b(e.addr))),t.setKeyId(e.keyId),t.setSignature($(e.signature)),a.addEnvelopeSignatures(t)}}catch(n){throw console.error("Trouble applying envelope signature",{acct:e,ix:t}),n}const c=new y;c.setTransaction(a);var d=Date.now();const u=await r(o.node,n.SendTransaction,c,s);var g=Date.now();let l=s.response();var f;return l.tag=t.tag,l.transactionId=(f=u.getId_asU8(),Buffer.from(f).toString("hex")),"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("FLOW::TX",{detail:{txId:l.transactionId,delta:g-d}})),l}const ne=e=>Buffer.from(e).toString("hex"),se=e=>Buffer.from(e).toString("hex"),oe=async(t,s={},o={})=>{switch(e(o.node,'SDK Send Error: Either opts.node or "accessNode.api" in config must be defined.'),e(s.ix,"SDK Send Error: context.ix must be defined."),t=await t,!0){case s.ix.isTransaction(t):return o.sendTransaction?o.sendTransaction(t,s,o):te(t,s,o);case s.ix.isGetTransactionStatus(t):return o.sendGetTransactionStatus?o.sendGetTransactionStatus(t,s,o):Q(t,s,o);case s.ix.isGetTransaction(t):return o.sendGetTransaction?o.sendGetTransaction(t,s,o):V(t,s,o);case s.ix.isScript(t):return o.sendExecuteScript?o.sendExecuteScript(t,s,o):A(t,s,o);case s.ix.isGetAccount(t):return o.sendGetAccount?o.sendGetAccount(t,s,o):T(t,s,o);case s.ix.isGetEvents(t):return o.sendGetEvents?o.sendGetEvents(t,s,o):z(t,s,o);case s.ix.isGetLatestBlock(t):return o.sendGetLatestBlock?o.sendGetLatestBlock(t,s,o):W(t,s,o);case s.ix.isGetBlock(t):return o.sendGetBlock?o.sendGetBlock(t,s,o):O(t,s,o);case s.ix.isGetBlockHeader(t):return o.sendGetBlockHeader?o.sendGetBlockHeader(t,s,o):R(t,s,o);case s.ix.isGetBlockById(t):return o.sendGetBlockById?o.sendGetBlockById(t,s,o):async function(t,s={},o={}){e(o.node,"SDK Send Get Block By ID Error: opts.node must be defined."),e(s.response,"SDK Send Get Block By ID Error: context.response must be defined."),t=await t;const r=new u;r.setId(Buffer.from(t.block.id,"hex"));const a=(await x(o.node,n.GetBlockByID,r,s)).getBlock(),i=a.getCollectionGuaranteesList(),c=a.getBlockSealsList(),d=a.getSignaturesList(),g=s.response();return g.tag=t.tag,g.block={id:ne(a.getId_asU8()),parentId:ne(a.getParentId_asU8()),height:a.getHeight(),timestamp:a.getTimestamp(),collectionGuarantees:i.map(e=>({collectionId:ne(e.getCollectionId_asU8()),signatures:e.getSignaturesList()})),blockSeals:c.map(e=>({blockId:ne(e.getBlockId_asU8()),executionReceiptId:ne(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:d},g}(t,s,o);case s.ix.isGetBlockByHeight(t):return o.sendGetBlockByHeight?o.sendGetBlockByHeight(t,s,o):async function(t,s={},o={}){e(o.node,"SDK Send Get Block By Height Error: opts.node must be defined."),e(s.response,"SDK Send Get Block By Height Error: context.response must be defined."),t=await t;const r=new g;r.setHeight(Number(t.block.height));const a=(await x(o.node,n.GetBlockByHeight,r,s)).getBlock(),i=a.getCollectionGuaranteesList(),c=a.getBlockSealsList(),d=a.getSignaturesList(),u=s.response();return u.tag=t.tag,u.block={id:se(a.getId_asU8()),parentId:se(a.getParentId_asU8()),height:a.getHeight(),timestamp:a.getTimestamp(),collectionGuarantees:i.map(e=>({collectionId:se(e.getCollectionId_asU8()),signatures:e.getSignaturesList()})),blockSeals:c.map(e=>({blockId:se(e.getBlockId_asU8()),executionReceiptId:se(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:d},u}(t,s,o);case s.ix.isGetCollection(t):return o.sendGetCollection?o.sendGetCollection(t,s,o):j(t,s,o);case s.ix.isPing(t):return o.sendPing?o.sendPing(t,s,o):Y(t,s,o);default:return t}};export{oe as send,A as sendExecuteScript,T as sendGetAccount,O as sendGetBlock,R as sendGetBlockHeader,j as sendGetCollection,z as sendGetEvents,W as sendGetLatestBlock,V as sendGetTransaction,Q as sendGetTransactionStatus,Y as sendPing,te as sendTransaction}; | ||
import{invariant as e}from"@onflow/util-invariant";import{ExecuteScriptAtBlockIDRequest as t,AccessAPI as n,ExecuteScriptAtBlockHeightRequest as s,ExecuteScriptAtLatestBlockRequest as r,GetAccountAtBlockHeightRequest as o,GetAccountAtLatestBlockRequest as a,GetBlockHeaderByIDRequest as i,GetBlockHeaderByHeightRequest as c,GetLatestBlockHeaderRequest as d,GetBlockByIDRequest as u,GetBlockByHeightRequest as g,GetLatestBlockRequest as l,GetCollectionByIDRequest as f,GetEventsForHeightRangeRequest as p,GetEventsForBlockIDsRequest as S,GetTransactionRequest as m,PingRequest as B,Transaction as k,SendTransactionRequest as y}from"@onflow/protobuf";import{grpc as b}from"@improbable-eng/grpc-web";import{NodeHttpTransport as h}from"@improbable-eng/grpc-web-node-http-transport";import{sansPrefix as I,withPrefix as w}from"@onflow/util-address";async function x(t,n,s,r){e(r.config,"SDK GRPC Unary Error: context.config must be defined.");const o=await r.config().get("grpc.metadata",{});return new Promise((e,r)=>{b.unary(n,{request:s,host:t,metadata:new b.Metadata(o),onEnd:({status:t,statusMessage:n,message:s})=>{t===b.Code.OK?e(s):r(new Error(n))}})})}b.setDefaultTransport(h());const E=(e,t)=>t.Buffer.from(JSON.stringify(e),"utf8");function G(e,t,n){let s=t.response();return s.tag=e.tag,s.encodedData=JSON.parse(t.Buffer.from(n.getValue_asU8()).toString("utf8")),s}async function D(o,a={},i={}){return e(i.node,"SDK Send Execute Script Error: opts.node must be defined."),e(a.response,"SDK Send Execute Script Error: context.response must be defined."),e(a.Buffer,"SDK Send Execute Script Error: context.Buffer must be defined."),(o=await o).block.id?await async function(e,s,r){const o=r.unary||x,a=new t;a.setBlockId(((e,t)=>t.Buffer.from(e,"hex"))(e.block.id,s));const i=s.Buffer.from(e.message.cadence,"utf8");e.message.arguments.forEach(t=>a.addArguments(E(e.arguments[t].asArgument,s))),a.setScript(i);const c=await o(r.node,n.ExecuteScriptAtBlockID,a,s);return G(e,s,c)}(o,a,i):o.block.height?await async function(e,t,r){const o=r.unary||x,a=new s;a.setBlockHeight(Number(e.block.height));const i=t.Buffer.from(e.message.cadence,"utf8");e.message.arguments.forEach(n=>a.addArguments(E(e.arguments[n].asArgument,t))),a.setScript(i);const c=await o(r.node,n.ExecuteScriptAtBlockHeight,a,t);return G(e,t,c)}(o,a,i):await async function(e,t,s){const o=s.unary||x,a=new r,i=t.Buffer.from(e.message.cadence,"utf8");e.message.arguments.forEach(n=>a.addArguments(E(e.arguments[n].asArgument,t))),a.setScript(i);const c=await o(s.node,n.ExecuteScriptAtLatestBlock,a,t);return G(e,t,c)}(o,a,i)}function A(){return A=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},A.apply(this,arguments)}const K=(e,t)=>t.Buffer.from(e).toString("hex"),L=(e,t)=>((e,t,n)=>n.Buffer.from(e.padStart(16,0),"hex"))(e,0,t),v={1:"SHA2_256",2:"SHA2_384",3:"SHA3_256",4:"SHA3_384",5:"KMAC128_BLS_BLS12_381"},_={1:"ECDSA_P256",2:"ECDSA_secp256k1",3:"BLS_BLS12_381"};function T(e,t,n){let s=t.response();s.tag=e.tag;const r=n.getAccount();let o;const a=(o=r.getContractsMap())?o.getEntryList().reduce((e,n)=>A({},e,{[n[0]]:t.Buffer.from(n[1]||new UInt8Array).toString("utf8")}),{}):{};return s.account={address:w(K(r.getAddress_asU8(),t)),balance:r.getBalance(),code:t.Buffer.from(r.getCode_asU8()||new UInt8Array).toString("utf8"),contracts:a,keys:r.getKeysList().map(e=>({index:e.getIndex(),publicKey:K(e.getPublicKey_asU8(),t),signAlgo:e.getSignAlgo(),signAlgoString:_[e.getSignAlgo()],hashAlgo:e.getHashAlgo(),hashAlgoString:v[e.getHashAlgo()],weight:e.getWeight(),sequenceNumber:e.getSequenceNumber(),revoked:e.getRevoked()}))},s}async function U(t,s={},r={}){return e(r.node,"SDK Send Get Account Error: opts.node must be defined."),e(s.response,"SDK Get Account Error: context.response must be defined."),e(s.Buffer,"SDK Get Account Error: context.Buffer must be defined."),null!==(t=await t).block.height?await async function(e,t,s){const r=s.unary||x,a=new o;return a.setBlockHeight(Number(e.block.height)),a.setAddress(L(I(e.account.addr),t)),T(e,t,await r(s.node,n.GetAccountAtBlockHeight,a,t))}(t,s,r):await async function(e,t,s){const r=s.unary||x,o=new a;return o.setAddress(L(I(e.account.addr),t)),T(e,t,await r(s.node,n.GetAccountAtLatestBlock,o,t))}(t,s,r)}const H=(e,t)=>t.Buffer.from(e).toString("hex");function N(e,t,n){const s=n.getBlock(),r=t.response();return r.tag=e.tag,r.blockHeader={id:H(s.getId_asU8(),t),parentId:H(s.getParentId_asU8(),t),height:s.getHeight(),timestamp:s.getTimestamp().toDate().toISOString()},r}async function R(t,s={},r={}){e(r.node,"SDK Send Get Block Header Error: opts.node must be defined."),e(s.response,"SDK Send Get Block Header Error: context.response must be defined."),e(s.Buffer,"SDK Send Get Block Header Error: context.Buffer must be defined.");const o=null!==(t=await t).block.height;return null!==t.block.id?await async function(e,t,s){const r=s.unary||x,o=new i;return o.setId(((e,t)=>t.Buffer.from(e,"hex"))(e.block.id,t)),N(e,t,await r(s.node,n.GetBlockHeaderByID,o,t))}(t,s,r):o?await async function(e,t,s){const r=s.unary||x,o=new c;return o.setHeight(Number(e.block.height)),N(e,t,await r(s.node,n.GetBlockHeaderByHeight,o,t))}(t,s,r):await async function(e,t,s){var r;const o=s.unary||x,a=new d;return null!=(r=e.block)&&r.isSealed&&a.setIsSealed(e.block.isSealed),N(e,t,await o(s.node,n.GetLatestBlockHeader,a,t))}(t,s,r)}const C=(e,t)=>t.Buffer.from(e).toString("hex");function P(e,t,n){const s=n.getBlock(),r=s.getCollectionGuaranteesList(),o=s.getBlockSealsList(),a=s.getSignaturesList().map(e=>C(e,t)),i=t.response();return i.tag=e.tag,i.block={id:C(s.getId_asU8(),t),parentId:C(s.getParentId_asU8(),t),height:s.getHeight(),timestamp:s.getTimestamp().toDate().toISOString(),collectionGuarantees:r.map(e=>({collectionId:C(e.getCollectionId_asU8(),t),signatures:e.getSignaturesList().map(e=>C(e,t))})),blockSeals:o.map(e=>({blockId:C(e.getBlockId_asU8(),t),executionReceiptId:C(e.getExecutionReceiptId_asU8(),t),executionReceiptSignatures:e.getExecutionReceiptSignaturesList().map(e=>C(e,t)),resultApprovalSignatures:e.getResultApprovalSignaturesList().map(e=>C(e,t))})),signatures:a},i}async function O(t,s={},r={}){e(r.node,"SDK Send Get Block Error: opts.node must be defined."),e(s.response,"SDK Send Get Block Error: context.response must be defined."),e(s.Buffer,"SDK Send Get Block Error: context.Buffer must be defined.");const o=null!==(t=await t).block.height;return null!==t.block.id?await async function(e,t,s){const r=s.unary||x,o=new u;return o.setId(((e,t)=>t.Buffer.from(e,"hex"))(e.block.id,t)),P(e,t,await r(s.node,n.GetBlockByID,o,t))}(t,s,r):o?await async function(e,t,s){const r=s.unary||x,o=new g;return o.setHeight(Number(e.block.height)),P(e,t,await r(s.node,n.GetBlockByHeight,o,t))}(t,s,r):await async function(e,t,s){var r;const o=s.unary||x,a=new l;return null!=(r=e.block)&&r.isSealed&&a.setIsSealed(e.block.isSealed),P(e,t,await o(s.node,n.GetLatestBlock,a,t))}(t,s,r)}const q=(e,t)=>t.Buffer.from(e).toString("hex");async function j(t,s={},r={}){e(r.node,"SDK Send Get Collection Error: opts.node must be defined."),e(s.response,"SDK Send Get Collection Error: context.response must be defined."),e(s.Buffer,"SDK Send Get Collection Error: context.Buffer must be defined.");const o=r.unary||x;t=await t;const a=new f;a.setId(((e,t)=>t.Buffer.from(e,"hex"))(t.collection.id,s));const i=(await o(r.node,n.GetCollectionByID,a,s)).getCollection(),c=s.response();return c.tag=t.tag,c.collection={id:q(i.getId_asU8(),s),transactionIds:i.getTransactionIdsList().map(e=>q(e,s))},c}const J=(e,t)=>t.Buffer.from(e).toString("hex");function M(e,t,n){let s=t.response();s.tag=e.tag;const r=n.getResultsList();return s.events=r.reduce((e,n)=>{const s=J(n.getBlockId_asU8(),t),r=n.getBlockHeight(),o=n.getBlockTimestamp().toDate().toISOString();return n.getEventsList().forEach(n=>{e.push({blockId:s,blockHeight:r,blockTimestamp:o,type:n.getType(),transactionId:J(n.getTransactionId_asU8(),t),transactionIndex:n.getTransactionIndex(),eventIndex:n.getEventIndex(),payload:JSON.parse(t.Buffer.from(n.getPayload_asU8()).toString("utf8"))})}),e},[]),s}async function z(t,s={},r={}){e(r.node,"SDK Send Get Events Error: opts.node must be defined."),e(s.response,"SDK Send Get Events Error: context.response must be defined."),e(s.Buffer,"SDK Send Get Events Error: context.Buffer must be defined.");const o=null!==(t=await t).events.start,a=Array.isArray(t.events.blockIds)&&t.events.blockIds.length>0;return e(o||a,"SendGetEventsError: Unable to determine which get events request to send. Either a block height range, or block IDs must be specified."),o?await async function(e,t,s){const r=s.unary||x,o=new p;return o.setType(e.events.eventType),o.setStartHeight(Number(e.events.start)),o.setEndHeight(Number(e.events.end)),M(e,t,await r(s.node,n.GetEventsForHeightRange,o,t))}(t,s,r):await async function(e,t,s){const r=s.unary||x,o=new S;o.setType(e.events.eventType),e.events.blockIds.forEach(e=>o.addBlockIds(((e,t)=>t.Buffer.from(e,"hex"))(e,t)));const a=await r(s.node,n.GetEventsForBlockIDs,o,t);return M(e,t,a)}(t,s,r)}const F=(e,t)=>t.Buffer.from(e).toString("hex");async function W(t,s={},r={}){e(r.node,"SDK Send Get Latest Block Error: opts.node must be defined."),e(s.response,"SDK Send Get Latest Block Error: context.response must be defined."),e(s.Buffer,"SDK Send Get Latest Block Error: context.Buffer must be defined."),t=await t;const o=new l;t.latestBlock&&t.latestBlock.isSealed&&(o.setIsSealed(t.latestBlock.isSealed),console.error("\n %c@onflow/send Deprecation Notice\n ========================\n\n Operating upon data of the latestBlock field of the interaction object is deprecated and will no longer be recognized in future releases of @onflow/send.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/send/WARNINGS.md#0001-Deprecating-latestBlock-field\n\n =======================\n ".replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")),t.block&&t.block.isSealed&&o.setIsSealed(t.block.isSealed);const a=(await x(r.node,n.GetLatestBlock,o,s)).getBlock(),i=a.getCollectionGuaranteesList(),c=a.getBlockSealsList(),d=a.getSignaturesList(),u=s.response();return u.tag=t.tag,u.block={id:F(a.getId_asU8(),s),parentId:F(a.getParentId_asU8(),s),height:a.getHeight(),timestamp:a.getTimestamp(),collectionGuarantees:i.map(e=>({collectionId:F(e.getCollectionId_asU8(),s),signatures:e.getSignaturesList()})),blockSeals:c.map(e=>({blockId:F(e.getBlockId_asU8(),s),executionReceiptId:F(e.getExecutionReceiptId_asU8(),s),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:d},u}const X=(e,t)=>t.Buffer.from(e).toString("hex");async function V(t,s={},r={}){e(r.node,"SDK Send Get Transaction Error: opts.node must be defined."),e(s.response,"SDK Send Get Transaction Error: context.response must be defined."),e(s.Buffer,"SDK Send Get Transaction Error: context.Buffer must be defined.");const o=r.unary||x;t=await t;const a=new m;a.setId(((e,t)=>t.Buffer.from(e,"hex"))(t.transaction.id,s));const i=await o(r.node,n.GetTransaction,a,s);let c=s.response();c.tag=t.tag;const d=e=>({address:X(e.getAddress_asU8(),s),keyId:e.getKeyId(),signature:X(e.getSignature_asU8(),s)});let u=i.getTransaction();var g;return c.transaction={script:s.Buffer.from(u.getScript_asU8()).toString("utf8"),args:u.getArgumentsList().map(e=>JSON.parse(s.Buffer.from(e).toString("utf8"))),referenceBlockId:X(u.getReferenceBlockId_asU8(),s),gasLimit:u.getGasLimit(),proposalKey:(g=u.getProposalKey(),{address:X(g.getAddress_asU8(),s),keyId:g.getKeyId(),sequenceNumber:g.getSequenceNumber()}),payer:X(u.getPayer_asU8(),s),authorizers:u.getAuthorizersList().map(e=>X(e,s)),payloadSignatures:u.getPayloadSignaturesList().map(d),envelopeSignatures:u.getEnvelopeSignaturesList().map(d)},c}const Z={0:"UNKNOWN",1:"PENDING",2:"FINALIZED",3:"EXECUTED",4:"SEALED",5:"EXPIRED"},Q=(e,t)=>t.Buffer.from(e).toString("hex");async function Y(t,s={},r={}){e(r.node,"SDK Send Get Transaction Status Error: opts.node must be defined."),e(s.response,"SDK Send Get Transaction Status Error: context.response must be defined."),e(s.Buffer,"SDK Send Get Transaction Status Error: context.Buffer must be defined.");const o=r.unary||x;t=await t;const a=new m;a.setId(((e,t)=>t.Buffer.from(e,"hex"))(t.transaction.id,s));const i=await o(r.node,n.GetTransactionResult,a,s);let c=i.getEventsList(),d=s.response();return d.tag=t.tag,d.transactionStatus={status:i.getStatus(),statusString:Z[i.getStatus()],statusCode:i.getStatusCode(),errorMessage:i.getErrorMessage(),events:c.map(e=>({type:e.getType(),transactionId:Q(e.getTransactionId_asU8(),s),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:JSON.parse(s.Buffer.from(e.getPayload_asU8()).toString("utf8"))}))},d}async function $(t,s={},r={}){e(r.node,"SDK Send Ping Error: opts.node must be defined."),e(s.response,"SDK Send Ping Error: context.response must be defined.");const o=r.unary||x;t=await t;const a=new B;await o(r.node,n.Ping,a,s);let i=s.response();return i.tag=t.tag,i}const ee=(e,t)=>t.Buffer.from(e,"hex"),te=(e,t)=>((e,t,n)=>n.Buffer.from(e.padStart(16,0),"hex"))(e,0,t);async function ne(t,s={},r={}){e(r.node,"SDK Send Transaction Error: opts.node must be defined."),e(s.response,"SDK Send Transaction Error: context.response must be defined."),e(s.Buffer,"SDK Send Transaction Error: context.Buffer must be defined.");const o=r.unary||x;t=await t;const a=new k;a.setScript(((e,t)=>t.Buffer.from(e,"utf8"))(t.message.cadence,s)),a.setGasLimit(t.message.computeLimit),a.setReferenceBlockId(t.message.refBlock?ee(t.message.refBlock,s):null),a.setPayer(te(I(t.accounts[Array.isArray(t.payer)?t.payer[0]:t.payer].addr),s)),t.message.arguments.forEach(e=>a.addArguments(((e,t)=>t.Buffer.from(JSON.stringify(e),"utf8"))(t.arguments[e].asArgument,s))),t.authorizations.map(e=>t.accounts[e].addr).reduce((e,t)=>e.find(e=>e===t)?e:[...e,t],[]).forEach(e=>a.addAuthorizers(te(I(e),s)));const i=new k.ProposalKey;i.setAddress(te(I(t.accounts[t.proposer].addr),s)),i.setKeyId(t.accounts[t.proposer].keyId),i.setSequenceNumber(t.accounts[t.proposer].sequenceNum),a.setProposalKey(i);for(let e of Object.values(t.accounts))try{if(!e.role.payer&&null!=e.signature){const t=new k.Signature;t.setAddress(te(I(e.addr),s)),t.setKeyId(e.keyId),t.setSignature(ee(e.signature,s)),a.addPayloadSignatures(t)}}catch(n){throw console.error("Trouble applying payload signature",{acct:e,ix:t}),n}for(let e of Object.values(t.accounts))try{if(e.role.payer&&null!=e.signature){const t=new k.Signature;t.setAddress(te(I(e.addr),s)),t.setKeyId(e.keyId),t.setSignature(ee(e.signature,s)),a.addEnvelopeSignatures(t)}}catch(n){throw console.error("Trouble applying envelope signature",{acct:e,ix:t}),n}const c=new y;c.setTransaction(a);var d=Date.now();const u=await o(r.node,n.SendTransaction,c,s);var g=Date.now();let l=s.response();return l.tag=t.tag,l.transactionId=((e,t)=>t.Buffer.from(e).toString("hex"))(u.getId_asU8(),s),"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("FLOW::TX",{detail:{txId:l.transactionId,delta:g-d}})),l}const se=(e,t)=>t.Buffer.from(e).toString("hex"),re=(e,t)=>t.Buffer.from(e).toString("hex"),oe=async(t,s={},r={})=>{switch(e(r.node,'SDK Send Error: Either opts.node or "accessNode.api" in config must be defined.'),e(s.ix,"SDK Send Error: context.ix must be defined."),t=await t,!0){case s.ix.isTransaction(t):return r.sendTransaction?r.sendTransaction(t,s,r):ne(t,s,r);case s.ix.isGetTransactionStatus(t):return r.sendGetTransactionStatus?r.sendGetTransactionStatus(t,s,r):Y(t,s,r);case s.ix.isGetTransaction(t):return r.sendGetTransaction?r.sendGetTransaction(t,s,r):V(t,s,r);case s.ix.isScript(t):return r.sendExecuteScript?r.sendExecuteScript(t,s,r):D(t,s,r);case s.ix.isGetAccount(t):return r.sendGetAccount?r.sendGetAccount(t,s,r):U(t,s,r);case s.ix.isGetEvents(t):return r.sendGetEvents?r.sendGetEvents(t,s,r):z(t,s,r);case s.ix.isGetLatestBlock(t):return r.sendGetLatestBlock?r.sendGetLatestBlock(t,s,r):W(t,s,r);case s.ix.isGetBlock(t):return r.sendGetBlock?r.sendGetBlock(t,s,r):O(t,s,r);case s.ix.isGetBlockHeader(t):return r.sendGetBlockHeader?r.sendGetBlockHeader(t,s,r):R(t,s,r);case s.ix.isGetBlockById(t):return r.sendGetBlockById?r.sendGetBlockById(t,s,r):async function(t,s={},r={}){e(r.node,"SDK Send Get Block By ID Error: opts.node must be defined."),e(s.response,"SDK Send Get Block By ID Error: context.response must be defined."),e(s.Buffer,"SDK Send Get Block By ID Error: context.Buffer must be defined."),t=await t;const o=new u;o.setId(((e,t)=>t.Buffer.from(e,"hex"))(t.block.id,s));const a=(await x(r.node,n.GetBlockByID,o,s)).getBlock(),i=a.getCollectionGuaranteesList(),c=a.getBlockSealsList(),d=a.getSignaturesList(),g=s.response();return g.tag=t.tag,g.block={id:se(a.getId_asU8(),s),parentId:se(a.getParentId_asU8(),s),height:a.getHeight(),timestamp:a.getTimestamp(),collectionGuarantees:i.map(e=>({collectionId:se(e.getCollectionId_asU8(),s),signatures:e.getSignaturesList()})),blockSeals:c.map(e=>({blockId:se(e.getBlockId_asU8(),s),executionReceiptId:se(e.getExecutionReceiptId_asU8(),s),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:d},g}(t,s,r);case s.ix.isGetBlockByHeight(t):return r.sendGetBlockByHeight?r.sendGetBlockByHeight(t,s,r):async function(t,s={},r={}){e(r.node,"SDK Send Get Block By Height Error: opts.node must be defined."),e(s.response,"SDK Send Get Block By Height Error: context.response must be defined."),e(s.Buffer,"SDK Send Get Block By Height Error: context.Buffer must be defined."),t=await t;const o=new g;o.setHeight(Number(t.block.height));const a=(await x(r.node,n.GetBlockByHeight,o,s)).getBlock(),i=a.getCollectionGuaranteesList(),c=a.getBlockSealsList(),d=a.getSignaturesList(),u=s.response();return u.tag=t.tag,u.block={id:re(a.getId_asU8(),s),parentId:re(a.getParentId_asU8(),s),height:a.getHeight(),timestamp:a.getTimestamp(),collectionGuarantees:i.map(e=>({collectionId:re(e.getCollectionId_asU8(),s),signatures:e.getSignaturesList()})),blockSeals:c.map(e=>({blockId:re(e.getBlockId_asU8(),s),executionReceiptId:re(e.getExecutionReceiptId_asU8(),s),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:d},u}(t,s,r);case s.ix.isGetCollection(t):return r.sendGetCollection?r.sendGetCollection(t,s,r):j(t,s,r);case s.ix.isPing(t):return r.sendPing?r.sendPing(t,s,r):$(t,s,r);default:return t}};export{oe as send,D as sendExecuteScript,U as sendGetAccount,O as sendGetBlock,R as sendGetBlockHeader,j as sendGetCollection,z as sendGetEvents,W as sendGetLatestBlock,V as sendGetTransaction,Y as sendGetTransactionStatus,$ as sendPing,ne as sendTransaction}; | ||
//# sourceMappingURL=sdk-send-grpc.modern.js.map |
@@ -1,2 +0,2 @@ | ||
import{invariant as e}from"@onflow/util-invariant";import{ExecuteScriptAtLatestBlockRequest as t,AccessAPI as r,ExecuteScriptAtBlockHeightRequest as n,ExecuteScriptAtBlockIDRequest as o,GetAccountAtLatestBlockRequest as s,GetAccountAtBlockHeightRequest as i,GetLatestBlockHeaderRequest as a,GetBlockHeaderByHeightRequest as c,GetBlockHeaderByIDRequest as u,GetLatestBlockRequest as d,GetBlockByHeightRequest as l,GetBlockByIDRequest as g,GetCollectionByIDRequest as f,GetEventsForBlockIDsRequest as m,GetEventsForHeightRangeRequest as p,GetTransactionRequest as S,PingRequest as h,Transaction as v,SendTransactionRequest as B}from"@onflow/protobuf";import{grpc as k}from"@improbable-eng/grpc-web";import{NodeHttpTransport as y}from"@improbable-eng/grpc-web-node-http-transport";import{sansPrefix as I,withPrefix as b}from"@onflow/util-address";var P=function(t,r,n,o){try{return e(o.config,"SDK GRPC Unary Error: context.config must be defined."),Promise.resolve(o.config().get("grpc.metadata",{})).then(function(e){return new Promise(function(o,s){k.unary(r,{request:n,host:t,metadata:new k.Metadata(e),onEnd:function(e){var t=e.statusMessage;e.status===k.Code.OK?o(e.message):s(new Error(t))}})})})}catch(e){return Promise.reject(e)}};k.setDefaultTransport(y());var x=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e(n.node,"SDK Send Execute Script Error: opts.node must be defined."),e(r.response,"SDK Send Execute Script Error: context.response must be defined."),Promise.resolve(t).then(function(e){return t=e,Promise.resolve(t.block.id?A(t,r,n):t.block.height?G(t,r,n):E(t,r,n))})}catch(e){return Promise.reject(e)}},E=function(e,n,o){try{var s=o.unary||P,i=new t,a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return i.addArguments(L(e.arguments[t].asArgument))}),i.setScript(a),Promise.resolve(s(o.node,r.ExecuteScriptAtLatestBlock,i,n)).then(function(t){return D(e,n,t)})}catch(e){return Promise.reject(e)}},G=function(e,t,o){try{var s=o.unary||P,i=new n;i.setBlockHeight(Number(e.block.height));var a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return i.addArguments(L(e.arguments[t].asArgument))}),i.setScript(a),Promise.resolve(s(o.node,r.ExecuteScriptAtBlockHeight,i,t)).then(function(r){return D(e,t,r)})}catch(e){return Promise.reject(e)}},A=function(e,t,n){try{var s=n.unary||P,i=new o;i.setBlockId(w(e.block.id));var a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return i.addArguments(L(e.arguments[t].asArgument))}),i.setScript(a),Promise.resolve(s(n.node,r.ExecuteScriptAtBlockID,i,t)).then(function(r){return D(e,t,r)})}catch(e){return Promise.reject(e)}},L=function(e){return Buffer.from(JSON.stringify(e),"utf8")},w=function(e){return Buffer.from(e,"hex")};function D(e,t,r){var n=t.response();return n.tag=e.tag,n.encodedData=JSON.parse(Buffer.from(r.getValue_asU8()).toString("utf8")),n}function _(){return _=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_.apply(this,arguments)}var U=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e(n.node,"SDK Send Get Account Error: opts.node must be defined."),e(r.response,"SDK Get Account Error: context.response must be defined."),Promise.resolve(t).then(function(e){return t=e,Promise.resolve(null!==t.block.height?T(t,r,n):K(t,r,n))})}catch(e){return Promise.reject(e)}},K=function(e,t,n){try{var o=n.unary||P,i=new s;return i.setAddress(j(I(e.account.addr))),Promise.resolve(o(n.node,r.GetAccountAtLatestBlock,i,t)).then(function(r){return C(e,t,r)})}catch(e){return Promise.reject(e)}},T=function(e,t,n){try{var o=n.unary||P,s=new i;return s.setBlockHeight(Number(e.block.height)),s.setAddress(j(I(e.account.addr))),Promise.resolve(o(n.node,r.GetAccountAtBlockHeight,s,t)).then(function(r){return C(e,t,r)})}catch(e){return Promise.reject(e)}},H=function(e){return Buffer.from(e).toString("hex")},j=function(e){return Buffer.from(e.padStart(16,0),"hex")},N={1:"SHA2_256",2:"SHA2_384",3:"SHA3_256",4:"SHA3_384",5:"KMAC128_BLS_BLS12_381"},R={1:"ECDSA_P256",2:"ECDSA_secp256k1",3:"BLS_BLS12_381"};function C(e,t,r){var n=t.response();n.tag=e.tag;var o,s=r.getAccount(),i=(o=s.getContractsMap())?o.getEntryList().reduce(function(e,t){var r;return _({},e,((r={})[t[0]]=Buffer.from(t[1]||new UInt8Array).toString("utf8"),r))},{}):{};return n.account={address:b(H(s.getAddress_asU8())),balance:s.getBalance(),code:Buffer.from(s.getCode_asU8()||new UInt8Array).toString("utf8"),contracts:i,keys:s.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:H(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),signAlgoString:R[e.getSignAlgo()],hashAlgo:e.getHashAlgo(),hashAlgoString:N[e.getHashAlgo()],weight:e.getWeight(),sequenceNumber:e.getSequenceNumber(),revoked:e.getRevoked()}})},n}var O=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e(n.node,"SDK Send Get Block Header Error: opts.node must be defined."),e(r.response,"SDK Send Get Block Header Error: context.response must be defined."),Promise.resolve(t).then(function(e){var o=null!==(t=e).block.height;return Promise.resolve(null!==t.block.id?M(t,r,n):o?J(t,r,n):q(t,r,n))})}catch(e){return Promise.reject(e)}},q=function(e,t,n){try{var o,s=n.unary||P,i=new a;return null!=(o=e.block)&&o.isSealed&&i.setIsSealed(e.block.isSealed),Promise.resolve(s(n.node,r.GetLatestBlockHeader,i,t)).then(function(r){return W(e,t,r)})}catch(e){return Promise.reject(e)}},J=function(e,t,n){try{var o=n.unary||P,s=new c;return s.setHeight(Number(e.block.height)),Promise.resolve(o(n.node,r.GetBlockHeaderByHeight,s,t)).then(function(r){return W(e,t,r)})}catch(e){return Promise.reject(e)}},M=function(e,t,n){try{var o=n.unary||P,s=new u;return s.setId(F(e.block.id)),Promise.resolve(o(n.node,r.GetBlockHeaderByID,s,t)).then(function(r){return W(e,t,r)})}catch(e){return Promise.reject(e)}},z=function(e){return Buffer.from(e).toString("hex")},F=function(e){return Buffer.from(e,"hex")};function W(e,t,r){var n=r.getBlock(),o=t.response();return o.tag=e.tag,o.blockHeader={id:z(n.getId_asU8()),parentId:z(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp().toDate().toISOString()},o}var X=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e(n.node,"SDK Send Get Block Error: opts.node must be defined."),e(r.response,"SDK Send Get Block Error: context.response must be defined."),Promise.resolve(t).then(function(e){var o=null!==(t=e).block.height;return Promise.resolve(null!==t.block.id?Q(t,r,n):o?Z(t,r,n):V(t,r,n))})}catch(e){return Promise.reject(e)}},V=function(e,t,n){try{var o,s=n.unary||P,i=new d;return null!=(o=e.block)&&o.isSealed&&i.setIsSealed(e.block.isSealed),Promise.resolve(s(n.node,r.GetLatestBlock,i,t)).then(function(r){return ee(e,t,r)})}catch(e){return Promise.reject(e)}},Z=function(e,t,n){try{var o=n.unary||P,s=new l;return s.setHeight(Number(e.block.height)),Promise.resolve(o(n.node,r.GetBlockByHeight,s,t)).then(function(r){return ee(e,t,r)})}catch(e){return Promise.reject(e)}},Q=function(e,t,n){try{var o=n.unary||P,s=new g;return s.setId($(e.block.id)),Promise.resolve(o(n.node,r.GetBlockByID,s,t)).then(function(r){return ee(e,t,r)})}catch(e){return Promise.reject(e)}},Y=function(e){return Buffer.from(e).toString("hex")},$=function(e){return Buffer.from(e,"hex")};function ee(e,t,r){var n=r.getBlock(),o=n.getCollectionGuaranteesList(),s=n.getBlockSealsList(),i=n.getSignaturesList().map(Y),a=t.response();return a.tag=e.tag,a.block={id:Y(n.getId_asU8()),parentId:Y(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp().toDate().toISOString(),collectionGuarantees:o.map(function(e){return{collectionId:Y(e.getCollectionId_asU8()),signatures:e.getSignaturesList().map(Y)}}),blockSeals:s.map(function(e){return{blockId:Y(e.getBlockId_asU8()),executionReceiptId:Y(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList().map(Y),resultApprovalSignatures:e.getResultApprovalSignaturesList().map(Y)}}),signatures:i},a}var te=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e(o.node,"SDK Send Get Collection Error: opts.node must be defined."),e(n.response,"SDK Send Get Collection Error: context.response must be defined.");var s=o.unary||P;return Promise.resolve(t).then(function(e){t=e;var i=new f;return i.setId(ne(t.collection.id)),Promise.resolve(s(o.node,r.GetCollectionByID,i,n)).then(function(e){var r=e.getCollection(),o=n.response();return o.tag=t.tag,o.collection={id:re(r.getId_asU8()),transactionIds:r.getTransactionIdsList().map(re)},o})})}catch(e){return Promise.reject(e)}},re=function(e){return Buffer.from(e).toString("hex")},ne=function(e){return Buffer.from(e,"hex")},oe=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e(n.node,"SDK Send Get Events Error: opts.node must be defined."),e(r.response,"SDK Send Get Events Error: context.response must be defined."),Promise.resolve(t).then(function(o){var s=null!==(t=o).events.start,i=Array.isArray(t.events.blockIds)&&t.events.blockIds.length>0;return e(s||i,"SendGetEventsError: Unable to determine which get events request to send. Either a block height range, or block IDs must be specified."),Promise.resolve(s?ie(t,r,n):se(t,r,n))})}catch(e){return Promise.reject(e)}},se=function(e,t,n){try{var o=n.unary||P,s=new m;return s.setType(e.events.eventType),e.events.blockIds.forEach(function(e){return s.addBlockIds(ce(e))}),Promise.resolve(o(n.node,r.GetEventsForBlockIDs,s,t)).then(function(r){return ue(e,t,r)})}catch(e){return Promise.reject(e)}},ie=function(e,t,n){try{var o=n.unary||P,s=new p;return s.setType(e.events.eventType),s.setStartHeight(Number(e.events.start)),s.setEndHeight(Number(e.events.end)),Promise.resolve(o(n.node,r.GetEventsForHeightRange,s,t)).then(function(r){return ue(e,t,r)})}catch(e){return Promise.reject(e)}},ae=function(e){return Buffer.from(e).toString("hex")},ce=function(e){return Buffer.from(e,"hex")};function ue(e,t,r){var n=t.response();n.tag=e.tag;var o=r.getResultsList();return n.events=o.reduce(function(e,t){var r=ae(t.getBlockId_asU8()),n=t.getBlockHeight(),o=t.getBlockTimestamp().toDate().toISOString();return t.getEventsList().forEach(function(t){e.push({blockId:r,blockHeight:n,blockTimestamp:o,type:t.getType(),transactionId:ae(t.getTransactionId_asU8()),transactionIndex:t.getTransactionIndex(),eventIndex:t.getEventIndex(),payload:JSON.parse(Buffer.from(t.getPayload_asU8()).toString("utf8"))})}),e},[]),n}var de=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e(o.node,"SDK Send Get Latest Block Error: opts.node must be defined."),e(n.response,"SDK Send Get Latest Block Error: context.response must be defined."),Promise.resolve(t).then(function(e){t=e;var s=new d;return t.latestBlock&&t.latestBlock.isSealed&&(s.setIsSealed(t.latestBlock.isSealed),ge()),t.block&&t.block.isSealed&&s.setIsSealed(t.block.isSealed),Promise.resolve(P(o.node,r.GetLatestBlock,s,n)).then(function(e){var r=e.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),i=r.getSignaturesList(),a=n.response();return a.tag=t.tag,a.block={id:le(r.getId_asU8()),parentId:le(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:le(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:le(e.getBlockId_asU8()),executionReceiptId:le(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}},le=function(e){return Buffer.from(e).toString("hex")},ge=function(){console.error("\n %c@onflow/send Deprecation Notice\n ========================\n\n Operating upon data of the latestBlock field of the interaction object is deprecated and will no longer be recognized in future releases of @onflow/send.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/send/WARNINGS.md#0001-Deprecating-latestBlock-field\n\n =======================\n ".replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")},fe=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e(o.node,"SDK Send Get Transaction Error: opts.node must be defined."),e(n.response,"SDK Send Get Transaction Error: context.response must be defined.");var s=o.unary||P;return Promise.resolve(t).then(function(e){t=e;var i=new S;return i.setId(pe(t.transaction.id)),Promise.resolve(s(o.node,r.GetTransaction,i,n)).then(function(e){var r=n.response();r.tag=t.tag;var o,s=function(e){return{address:me(e.getAddress_asU8()),keyId:e.getKeyId(),signature:me(e.getSignature_asU8())}},i=e.getTransaction();return r.transaction={script:Buffer.from(i.getScript_asU8()).toString("utf8"),args:i.getArgumentsList().map(function(e){return JSON.parse(Buffer.from(e).toString("utf8"))}),referenceBlockId:me(i.getReferenceBlockId_asU8()),gasLimit:i.getGasLimit(),proposalKey:(o=i.getProposalKey(),{address:me(o.getAddress_asU8()),keyId:o.getKeyId(),sequenceNumber:o.getSequenceNumber()}),payer:me(i.getPayer_asU8()),authorizers:i.getAuthorizersList().map(me),payloadSignatures:i.getPayloadSignaturesList().map(s),envelopeSignatures:i.getEnvelopeSignaturesList().map(s)},r})})}catch(e){return Promise.reject(e)}},me=function(e){return Buffer.from(e).toString("hex")},pe=function(e){return Buffer.from(e,"hex")},Se=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e(o.node,"SDK Send Get Transaction Status Error: opts.node must be defined."),e(n.response,"SDK Send Get Transaction Status Error: context.response must be defined.");var s=o.unary||P;return Promise.resolve(t).then(function(e){t=e;var i=new S;return i.setId(Be(t.transaction.id)),Promise.resolve(s(o.node,r.GetTransactionResult,i,n)).then(function(e){var r=e.getEventsList(),o=n.response();return o.tag=t.tag,o.transactionStatus={status:e.getStatus(),statusString:he[e.getStatus()],statusCode:e.getStatusCode(),errorMessage:e.getErrorMessage(),events:r.map(function(e){return{type:e.getType(),transactionId:ve(e.getTransactionId_asU8()),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:JSON.parse(Buffer.from(e.getPayload_asU8()).toString("utf8"))}})},o})})}catch(e){return Promise.reject(e)}},he={0:"UNKNOWN",1:"PENDING",2:"FINALIZED",3:"EXECUTED",4:"SEALED",5:"EXPIRED"},ve=function(e){return Buffer.from(e).toString("hex")},Be=function(e){return Buffer.from(e,"hex")},ke=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e(o.node,"SDK Send Ping Error: opts.node must be defined."),e(n.response,"SDK Send Ping Error: context.response must be defined.");var s=o.unary||P;return Promise.resolve(t).then(function(e){t=e;var i=new h;return Promise.resolve(s(o.node,r.Ping,i,n)).then(function(e){var r=n.response();return r.tag=t.tag,r})})}catch(e){return Promise.reject(e)}},ye=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e(o.node,"SDK Send Transaction Error: opts.node must be defined."),e(n.response,"SDK Send Transaction Error: context.response must be defined.");var s=o.unary||P;return Promise.resolve(t).then(function(e){t=e;var i=new v;i.setScript(be(t.message.cadence)),i.setGasLimit(t.message.computeLimit),i.setReferenceBlockId(t.message.refBlock?Pe(t.message.refBlock):null),i.setPayer(xe(I(t.accounts[t.payer].addr))),t.message.arguments.forEach(function(e){return i.addArguments(Ee(t.arguments[e].asArgument))}),t.authorizations.map(function(e){return t.accounts[e].addr}).reduce(function(e,t){return e.find(function(e){return e===t})?e:[].concat(e,[t])},[]).forEach(function(e){return i.addAuthorizers(xe(I(e)))});var a=new v.ProposalKey;a.setAddress(xe(I(t.accounts[t.proposer].addr))),a.setKeyId(t.accounts[t.proposer].keyId),a.setSequenceNumber(t.accounts[t.proposer].sequenceNum),i.setProposalKey(a);for(var c=0,u=Object.values(t.accounts);c<u.length;c++){var d=u[c];try{if(!d.role.payer&&null!=d.signature){var l=new v.Signature;l.setAddress(xe(I(d.addr))),l.setKeyId(d.keyId),l.setSignature(Pe(d.signature)),i.addPayloadSignatures(l)}}catch(e){throw console.error("Trouble applying payload signature",{acct:d,ix:t}),e}}for(var g=0,f=Object.values(t.accounts);g<f.length;g++){var m=f[g];try{if(m.role.payer&&null!=m.signature){var p=new v.Signature;p.setAddress(xe(I(m.addr))),p.setKeyId(m.keyId),p.setSignature(Pe(m.signature)),i.addEnvelopeSignatures(p)}}catch(e){throw console.error("Trouble applying envelope signature",{acct:m,ix:t}),e}}var S=new B;S.setTransaction(i);var h=Date.now();return Promise.resolve(s(o.node,r.SendTransaction,S,n)).then(function(e){var r=Date.now(),o=n.response();return o.tag=t.tag,o.transactionId=Ie(e.getId_asU8()),"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("FLOW::TX",{detail:{txId:o.transactionId,delta:r-h}})),o})})}catch(e){return Promise.reject(e)}},Ie=function(e){return Buffer.from(e).toString("hex")},be=function(e){return Buffer.from(e,"utf8")},Pe=function(e){return Buffer.from(e,"hex")},xe=function(e){return Buffer.from(e.padStart(16,0),"hex")},Ee=function(e){return Buffer.from(JSON.stringify(e),"utf8")},Ge=function(e){return Buffer.from(e).toString("hex")},Ae=function(e){return Buffer.from(e).toString("hex")},Le=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e(o.node,'SDK Send Error: Either opts.node or "accessNode.api" in config must be defined.'),e(n.ix,"SDK Send Error: context.ix must be defined."),Promise.resolve(t).then(function(s){switch(t=s,!0){case n.ix.isTransaction(t):return o.sendTransaction?o.sendTransaction(t,n,o):ye(t,n,o);case n.ix.isGetTransactionStatus(t):return o.sendGetTransactionStatus?o.sendGetTransactionStatus(t,n,o):Se(t,n,o);case n.ix.isGetTransaction(t):return o.sendGetTransaction?o.sendGetTransaction(t,n,o):fe(t,n,o);case n.ix.isScript(t):return o.sendExecuteScript?o.sendExecuteScript(t,n,o):x(t,n,o);case n.ix.isGetAccount(t):return o.sendGetAccount?o.sendGetAccount(t,n,o):U(t,n,o);case n.ix.isGetEvents(t):return o.sendGetEvents?o.sendGetEvents(t,n,o):oe(t,n,o);case n.ix.isGetLatestBlock(t):return o.sendGetLatestBlock?o.sendGetLatestBlock(t,n,o):de(t,n,o);case n.ix.isGetBlock(t):return o.sendGetBlock?o.sendGetBlock(t,n,o):X(t,n,o);case n.ix.isGetBlockHeader(t):return o.sendGetBlockHeader?o.sendGetBlockHeader(t,n,o):O(t,n,o);case n.ix.isGetBlockById(t):return o.sendGetBlockById?o.sendGetBlockById(t,n,o):function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e(o.node,"SDK Send Get Block By ID Error: opts.node must be defined."),e(n.response,"SDK Send Get Block By ID Error: context.response must be defined."),Promise.resolve(t).then(function(e){t=e;var s=new g;return s.setId(Buffer.from(t.block.id,"hex")),Promise.resolve(P(o.node,r.GetBlockByID,s,n)).then(function(e){var r=e.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),i=r.getSignaturesList(),a=n.response();return a.tag=t.tag,a.block={id:Ge(r.getId_asU8()),parentId:Ge(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:Ge(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:Ge(e.getBlockId_asU8()),executionReceiptId:Ge(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}}(t,n,o);case n.ix.isGetBlockByHeight(t):return o.sendGetBlockByHeight?o.sendGetBlockByHeight(t,n,o):function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e(o.node,"SDK Send Get Block By Height Error: opts.node must be defined."),e(n.response,"SDK Send Get Block By Height Error: context.response must be defined."),Promise.resolve(t).then(function(e){t=e;var s=new l;return s.setHeight(Number(t.block.height)),Promise.resolve(P(o.node,r.GetBlockByHeight,s,n)).then(function(e){var r=e.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),i=r.getSignaturesList(),a=n.response();return a.tag=t.tag,a.block={id:Ae(r.getId_asU8()),parentId:Ae(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:Ae(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:Ae(e.getBlockId_asU8()),executionReceiptId:Ae(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}}(t,n,o);case n.ix.isGetCollection(t):return o.sendGetCollection?o.sendGetCollection(t,n,o):te(t,n,o);case n.ix.isPing(t):return o.sendPing?o.sendPing(t,n,o):ke(t,n,o);default:return t}})}catch(e){return Promise.reject(e)}};export{Le as send,x as sendExecuteScript,U as sendGetAccount,X as sendGetBlock,O as sendGetBlockHeader,te as sendGetCollection,oe as sendGetEvents,de as sendGetLatestBlock,fe as sendGetTransaction,Se as sendGetTransactionStatus,ke as sendPing,ye as sendTransaction}; | ||
import{invariant as e}from"@onflow/util-invariant";import{ExecuteScriptAtLatestBlockRequest as t,AccessAPI as r,ExecuteScriptAtBlockHeightRequest as n,ExecuteScriptAtBlockIDRequest as o,GetAccountAtLatestBlockRequest as s,GetAccountAtBlockHeightRequest as i,GetLatestBlockHeaderRequest as a,GetBlockHeaderByHeightRequest as u,GetBlockHeaderByIDRequest as c,GetLatestBlockRequest as d,GetBlockByHeightRequest as f,GetBlockByIDRequest as l,GetCollectionByIDRequest as g,GetEventsForBlockIDsRequest as m,GetEventsForHeightRangeRequest as p,GetTransactionRequest as S,PingRequest as h,Transaction as v,SendTransactionRequest as B}from"@onflow/protobuf";import{grpc as k}from"@improbable-eng/grpc-web";import{NodeHttpTransport as y}from"@improbable-eng/grpc-web-node-http-transport";import{sansPrefix as b,withPrefix as I}from"@onflow/util-address";var x=function(t,r,n,o){try{return e(o.config,"SDK GRPC Unary Error: context.config must be defined."),Promise.resolve(o.config().get("grpc.metadata",{})).then(function(e){return new Promise(function(o,s){k.unary(r,{request:n,host:t,metadata:new k.Metadata(e),onEnd:function(e){var t=e.statusMessage;e.status===k.Code.OK?o(e.message):s(new Error(t))}})})})}catch(e){return Promise.reject(e)}};k.setDefaultTransport(y());var E=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e(n.node,"SDK Send Execute Script Error: opts.node must be defined."),e(r.response,"SDK Send Execute Script Error: context.response must be defined."),e(r.Buffer,"SDK Send Execute Script Error: context.Buffer must be defined."),Promise.resolve(t).then(function(e){return t=e,Promise.resolve(t.block.id?D(t,r,n):t.block.height?G(t,r,n):P(t,r,n))})}catch(e){return Promise.reject(e)}},P=function(e,n,o){try{var s=o.unary||x,i=new t,a=n.Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return i.addArguments(A(e.arguments[t].asArgument,n))}),i.setScript(a),Promise.resolve(s(o.node,r.ExecuteScriptAtLatestBlock,i,n)).then(function(t){return L(e,n,t)})}catch(e){return Promise.reject(e)}},G=function(e,t,o){try{var s=o.unary||x,i=new n;i.setBlockHeight(Number(e.block.height));var a=t.Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(r){return i.addArguments(A(e.arguments[r].asArgument,t))}),i.setScript(a),Promise.resolve(s(o.node,r.ExecuteScriptAtBlockHeight,i,t)).then(function(r){return L(e,t,r)})}catch(e){return Promise.reject(e)}},D=function(e,t,n){try{var s=n.unary||x,i=new o;i.setBlockId(K(e.block.id,t));var a=t.Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(r){return i.addArguments(A(e.arguments[r].asArgument,t))}),i.setScript(a),Promise.resolve(s(n.node,r.ExecuteScriptAtBlockID,i,t)).then(function(r){return L(e,t,r)})}catch(e){return Promise.reject(e)}},A=function(e,t){return t.Buffer.from(JSON.stringify(e),"utf8")},K=function(e,t){return t.Buffer.from(e,"hex")};function L(e,t,r){var n=t.response();return n.tag=e.tag,n.encodedData=JSON.parse(t.Buffer.from(r.getValue_asU8()).toString("utf8")),n}function w(){return w=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},w.apply(this,arguments)}var _=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e(n.node,"SDK Send Get Account Error: opts.node must be defined."),e(r.response,"SDK Get Account Error: context.response must be defined."),e(r.Buffer,"SDK Get Account Error: context.Buffer must be defined."),Promise.resolve(t).then(function(e){return t=e,Promise.resolve(null!==t.block.height?U(t,r,n):T(t,r,n))})}catch(e){return Promise.reject(e)}},T=function(e,t,n){try{var o=n.unary||x,i=new s;return i.setAddress(j(b(e.account.addr),t)),Promise.resolve(o(n.node,r.GetAccountAtLatestBlock,i,t)).then(function(r){return C(e,t,r)})}catch(e){return Promise.reject(e)}},U=function(e,t,n){try{var o=n.unary||x,s=new i;return s.setBlockHeight(Number(e.block.height)),s.setAddress(j(b(e.account.addr),t)),Promise.resolve(o(n.node,r.GetAccountAtBlockHeight,s,t)).then(function(r){return C(e,t,r)})}catch(e){return Promise.reject(e)}},H=function(e,t){return t.Buffer.from(e).toString("hex")},j=function(e,t){return function(e,t,r){return r.Buffer.from(e.padStart(16,0),"hex")}(e,0,t)},N={1:"SHA2_256",2:"SHA2_384",3:"SHA3_256",4:"SHA3_384",5:"KMAC128_BLS_BLS12_381"},R={1:"ECDSA_P256",2:"ECDSA_secp256k1",3:"BLS_BLS12_381"};function C(e,t,r){var n=t.response();n.tag=e.tag;var o,s=r.getAccount(),i=(o=s.getContractsMap())?o.getEntryList().reduce(function(e,r){var n;return w({},e,((n={})[r[0]]=t.Buffer.from(r[1]||new UInt8Array).toString("utf8"),n))},{}):{};return n.account={address:I(H(s.getAddress_asU8(),t)),balance:s.getBalance(),code:t.Buffer.from(s.getCode_asU8()||new UInt8Array).toString("utf8"),contracts:i,keys:s.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:H(e.getPublicKey_asU8(),t),signAlgo:e.getSignAlgo(),signAlgoString:R[e.getSignAlgo()],hashAlgo:e.getHashAlgo(),hashAlgoString:N[e.getHashAlgo()],weight:e.getWeight(),sequenceNumber:e.getSequenceNumber(),revoked:e.getRevoked()}})},n}var O=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e(n.node,"SDK Send Get Block Header Error: opts.node must be defined."),e(r.response,"SDK Send Get Block Header Error: context.response must be defined."),e(r.Buffer,"SDK Send Get Block Header Error: context.Buffer must be defined."),Promise.resolve(t).then(function(e){var o=null!==(t=e).block.height;return Promise.resolve(null!==t.block.id?M(t,r,n):o?J(t,r,n):q(t,r,n))})}catch(e){return Promise.reject(e)}},q=function(e,t,n){try{var o,s=n.unary||x,i=new a;return null!=(o=e.block)&&o.isSealed&&i.setIsSealed(e.block.isSealed),Promise.resolve(s(n.node,r.GetLatestBlockHeader,i,t)).then(function(r){return W(e,t,r)})}catch(e){return Promise.reject(e)}},J=function(e,t,n){try{var o=n.unary||x,s=new u;return s.setHeight(Number(e.block.height)),Promise.resolve(o(n.node,r.GetBlockHeaderByHeight,s,t)).then(function(r){return W(e,t,r)})}catch(e){return Promise.reject(e)}},M=function(e,t,n){try{var o=n.unary||x,s=new c;return s.setId(F(e.block.id,t)),Promise.resolve(o(n.node,r.GetBlockHeaderByID,s,t)).then(function(r){return W(e,t,r)})}catch(e){return Promise.reject(e)}},z=function(e,t){return t.Buffer.from(e).toString("hex")},F=function(e,t){return t.Buffer.from(e,"hex")};function W(e,t,r){var n=r.getBlock(),o=t.response();return o.tag=e.tag,o.blockHeader={id:z(n.getId_asU8(),t),parentId:z(n.getParentId_asU8(),t),height:n.getHeight(),timestamp:n.getTimestamp().toDate().toISOString()},o}var X=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e(n.node,"SDK Send Get Block Error: opts.node must be defined."),e(r.response,"SDK Send Get Block Error: context.response must be defined."),e(r.Buffer,"SDK Send Get Block Error: context.Buffer must be defined."),Promise.resolve(t).then(function(e){var o=null!==(t=e).block.height;return Promise.resolve(null!==t.block.id?Q(t,r,n):o?Z(t,r,n):V(t,r,n))})}catch(e){return Promise.reject(e)}},V=function(e,t,n){try{var o,s=n.unary||x,i=new d;return null!=(o=e.block)&&o.isSealed&&i.setIsSealed(e.block.isSealed),Promise.resolve(s(n.node,r.GetLatestBlock,i,t)).then(function(r){return ee(e,t,r)})}catch(e){return Promise.reject(e)}},Z=function(e,t,n){try{var o=n.unary||x,s=new f;return s.setHeight(Number(e.block.height)),Promise.resolve(o(n.node,r.GetBlockByHeight,s,t)).then(function(r){return ee(e,t,r)})}catch(e){return Promise.reject(e)}},Q=function(e,t,n){try{var o=n.unary||x,s=new l;return s.setId($(e.block.id,t)),Promise.resolve(o(n.node,r.GetBlockByID,s,t)).then(function(r){return ee(e,t,r)})}catch(e){return Promise.reject(e)}},Y=function(e,t){return t.Buffer.from(e).toString("hex")},$=function(e,t){return t.Buffer.from(e,"hex")};function ee(e,t,r){var n=r.getBlock(),o=n.getCollectionGuaranteesList(),s=n.getBlockSealsList(),i=n.getSignaturesList().map(function(e){return Y(e,t)}),a=t.response();return a.tag=e.tag,a.block={id:Y(n.getId_asU8(),t),parentId:Y(n.getParentId_asU8(),t),height:n.getHeight(),timestamp:n.getTimestamp().toDate().toISOString(),collectionGuarantees:o.map(function(e){return{collectionId:Y(e.getCollectionId_asU8(),t),signatures:e.getSignaturesList().map(function(e){return Y(e,t)})}}),blockSeals:s.map(function(e){return{blockId:Y(e.getBlockId_asU8(),t),executionReceiptId:Y(e.getExecutionReceiptId_asU8(),t),executionReceiptSignatures:e.getExecutionReceiptSignaturesList().map(function(e){return Y(e,t)}),resultApprovalSignatures:e.getResultApprovalSignaturesList().map(function(e){return Y(e,t)})}}),signatures:i},a}var te=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e(o.node,"SDK Send Get Collection Error: opts.node must be defined."),e(n.response,"SDK Send Get Collection Error: context.response must be defined."),e(n.Buffer,"SDK Send Get Collection Error: context.Buffer must be defined.");var s=o.unary||x;return Promise.resolve(t).then(function(e){t=e;var i=new g;return i.setId(ne(t.collection.id,n)),Promise.resolve(s(o.node,r.GetCollectionByID,i,n)).then(function(e){var r=e.getCollection(),o=n.response();return o.tag=t.tag,o.collection={id:re(r.getId_asU8(),n),transactionIds:r.getTransactionIdsList().map(function(e){return re(e,n)})},o})})}catch(e){return Promise.reject(e)}},re=function(e,t){return t.Buffer.from(e).toString("hex")},ne=function(e,t){return t.Buffer.from(e,"hex")},oe=function(t,r,n){void 0===r&&(r={}),void 0===n&&(n={});try{return e(n.node,"SDK Send Get Events Error: opts.node must be defined."),e(r.response,"SDK Send Get Events Error: context.response must be defined."),e(r.Buffer,"SDK Send Get Events Error: context.Buffer must be defined."),Promise.resolve(t).then(function(o){var s=null!==(t=o).events.start,i=Array.isArray(t.events.blockIds)&&t.events.blockIds.length>0;return e(s||i,"SendGetEventsError: Unable to determine which get events request to send. Either a block height range, or block IDs must be specified."),Promise.resolve(s?ie(t,r,n):se(t,r,n))})}catch(e){return Promise.reject(e)}},se=function(e,t,n){try{var o=n.unary||x,s=new m;return s.setType(e.events.eventType),e.events.blockIds.forEach(function(e){return s.addBlockIds(ue(e,t))}),Promise.resolve(o(n.node,r.GetEventsForBlockIDs,s,t)).then(function(r){return ce(e,t,r)})}catch(e){return Promise.reject(e)}},ie=function(e,t,n){try{var o=n.unary||x,s=new p;return s.setType(e.events.eventType),s.setStartHeight(Number(e.events.start)),s.setEndHeight(Number(e.events.end)),Promise.resolve(o(n.node,r.GetEventsForHeightRange,s,t)).then(function(r){return ce(e,t,r)})}catch(e){return Promise.reject(e)}},ae=function(e,t){return t.Buffer.from(e).toString("hex")},ue=function(e,t){return t.Buffer.from(e,"hex")};function ce(e,t,r){var n=t.response();n.tag=e.tag;var o=r.getResultsList();return n.events=o.reduce(function(e,r){var n=ae(r.getBlockId_asU8(),t),o=r.getBlockHeight(),s=r.getBlockTimestamp().toDate().toISOString();return r.getEventsList().forEach(function(r){e.push({blockId:n,blockHeight:o,blockTimestamp:s,type:r.getType(),transactionId:ae(r.getTransactionId_asU8(),t),transactionIndex:r.getTransactionIndex(),eventIndex:r.getEventIndex(),payload:JSON.parse(t.Buffer.from(r.getPayload_asU8()).toString("utf8"))})}),e},[]),n}var de=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e(o.node,"SDK Send Get Latest Block Error: opts.node must be defined."),e(n.response,"SDK Send Get Latest Block Error: context.response must be defined."),e(n.Buffer,"SDK Send Get Latest Block Error: context.Buffer must be defined."),Promise.resolve(t).then(function(e){t=e;var s=new d;return t.latestBlock&&t.latestBlock.isSealed&&(s.setIsSealed(t.latestBlock.isSealed),le()),t.block&&t.block.isSealed&&s.setIsSealed(t.block.isSealed),Promise.resolve(x(o.node,r.GetLatestBlock,s,n)).then(function(e){var r=e.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),i=r.getSignaturesList(),a=n.response();return a.tag=t.tag,a.block={id:fe(r.getId_asU8(),n),parentId:fe(r.getParentId_asU8(),n),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:fe(e.getCollectionId_asU8(),n),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:fe(e.getBlockId_asU8(),n),executionReceiptId:fe(e.getExecutionReceiptId_asU8(),n),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}},fe=function(e,t){return t.Buffer.from(e).toString("hex")},le=function(){console.error("\n %c@onflow/send Deprecation Notice\n ========================\n\n Operating upon data of the latestBlock field of the interaction object is deprecated and will no longer be recognized in future releases of @onflow/send.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/send/WARNINGS.md#0001-Deprecating-latestBlock-field\n\n =======================\n ".replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")},ge=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e(o.node,"SDK Send Get Transaction Error: opts.node must be defined."),e(n.response,"SDK Send Get Transaction Error: context.response must be defined."),e(n.Buffer,"SDK Send Get Transaction Error: context.Buffer must be defined.");var s=o.unary||x;return Promise.resolve(t).then(function(e){t=e;var i=new S;return i.setId(pe(t.transaction.id,n)),Promise.resolve(s(o.node,r.GetTransaction,i,n)).then(function(e){var r=n.response();r.tag=t.tag;var o,s=function(e){return{address:me(e.getAddress_asU8(),n),keyId:e.getKeyId(),signature:me(e.getSignature_asU8(),n)}},i=e.getTransaction();return r.transaction={script:n.Buffer.from(i.getScript_asU8()).toString("utf8"),args:i.getArgumentsList().map(function(e){return JSON.parse(n.Buffer.from(e).toString("utf8"))}),referenceBlockId:me(i.getReferenceBlockId_asU8(),n),gasLimit:i.getGasLimit(),proposalKey:(o=i.getProposalKey(),{address:me(o.getAddress_asU8(),n),keyId:o.getKeyId(),sequenceNumber:o.getSequenceNumber()}),payer:me(i.getPayer_asU8(),n),authorizers:i.getAuthorizersList().map(function(e){return me(e,n)}),payloadSignatures:i.getPayloadSignaturesList().map(s),envelopeSignatures:i.getEnvelopeSignaturesList().map(s)},r})})}catch(e){return Promise.reject(e)}},me=function(e,t){return t.Buffer.from(e).toString("hex")},pe=function(e,t){return t.Buffer.from(e,"hex")},Se=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e(o.node,"SDK Send Get Transaction Status Error: opts.node must be defined."),e(n.response,"SDK Send Get Transaction Status Error: context.response must be defined."),e(n.Buffer,"SDK Send Get Transaction Status Error: context.Buffer must be defined.");var s=o.unary||x;return Promise.resolve(t).then(function(e){t=e;var i=new S;return i.setId(Be(t.transaction.id,n)),Promise.resolve(s(o.node,r.GetTransactionResult,i,n)).then(function(e){var r=e.getEventsList(),o=n.response();return o.tag=t.tag,o.transactionStatus={status:e.getStatus(),statusString:he[e.getStatus()],statusCode:e.getStatusCode(),errorMessage:e.getErrorMessage(),events:r.map(function(e){return{type:e.getType(),transactionId:ve(e.getTransactionId_asU8(),n),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:JSON.parse(n.Buffer.from(e.getPayload_asU8()).toString("utf8"))}})},o})})}catch(e){return Promise.reject(e)}},he={0:"UNKNOWN",1:"PENDING",2:"FINALIZED",3:"EXECUTED",4:"SEALED",5:"EXPIRED"},ve=function(e,t){return t.Buffer.from(e).toString("hex")},Be=function(e,t){return t.Buffer.from(e,"hex")},ke=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e(o.node,"SDK Send Ping Error: opts.node must be defined."),e(n.response,"SDK Send Ping Error: context.response must be defined.");var s=o.unary||x;return Promise.resolve(t).then(function(e){t=e;var i=new h;return Promise.resolve(s(o.node,r.Ping,i,n)).then(function(e){var r=n.response();return r.tag=t.tag,r})})}catch(e){return Promise.reject(e)}},ye=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{e(o.node,"SDK Send Transaction Error: opts.node must be defined."),e(n.response,"SDK Send Transaction Error: context.response must be defined."),e(n.Buffer,"SDK Send Transaction Error: context.Buffer must be defined.");var s=o.unary||x;return Promise.resolve(t).then(function(e){t=e;var i=new v;i.setScript(Ie(t.message.cadence,n)),i.setGasLimit(t.message.computeLimit),i.setReferenceBlockId(t.message.refBlock?xe(t.message.refBlock,n):null),i.setPayer(Ee(b(t.accounts[Array.isArray(t.payer)?t.payer[0]:t.payer].addr),n)),t.message.arguments.forEach(function(e){return i.addArguments(Pe(t.arguments[e].asArgument,n))}),t.authorizations.map(function(e){return t.accounts[e].addr}).reduce(function(e,t){return e.find(function(e){return e===t})?e:[].concat(e,[t])},[]).forEach(function(e){return i.addAuthorizers(Ee(b(e),n))});var a=new v.ProposalKey;a.setAddress(Ee(b(t.accounts[t.proposer].addr),n)),a.setKeyId(t.accounts[t.proposer].keyId),a.setSequenceNumber(t.accounts[t.proposer].sequenceNum),i.setProposalKey(a);for(var u=0,c=Object.values(t.accounts);u<c.length;u++){var d=c[u];try{if(!d.role.payer&&null!=d.signature){var f=new v.Signature;f.setAddress(Ee(b(d.addr),n)),f.setKeyId(d.keyId),f.setSignature(xe(d.signature,n)),i.addPayloadSignatures(f)}}catch(e){throw console.error("Trouble applying payload signature",{acct:d,ix:t}),e}}for(var l=0,g=Object.values(t.accounts);l<g.length;l++){var m=g[l];try{if(m.role.payer&&null!=m.signature){var p=new v.Signature;p.setAddress(Ee(b(m.addr),n)),p.setKeyId(m.keyId),p.setSignature(xe(m.signature,n)),i.addEnvelopeSignatures(p)}}catch(e){throw console.error("Trouble applying envelope signature",{acct:m,ix:t}),e}}var S=new B;S.setTransaction(i);var h=Date.now();return Promise.resolve(s(o.node,r.SendTransaction,S,n)).then(function(e){var r=Date.now(),o=n.response();return o.tag=t.tag,o.transactionId=be(e.getId_asU8(),n),"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("FLOW::TX",{detail:{txId:o.transactionId,delta:r-h}})),o})})}catch(e){return Promise.reject(e)}},be=function(e,t){return t.Buffer.from(e).toString("hex")},Ie=function(e,t){return t.Buffer.from(e,"utf8")},xe=function(e,t){return t.Buffer.from(e,"hex")},Ee=function(e,t){return function(e,t,r){return r.Buffer.from(e.padStart(16,0),"hex")}(e,0,t)},Pe=function(e,t){return t.Buffer.from(JSON.stringify(e),"utf8")},Ge=function(e,t){return t.Buffer.from(e).toString("hex")},De=function(e,t){return t.Buffer.from(e).toString("hex")},Ae=function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e(o.node,'SDK Send Error: Either opts.node or "accessNode.api" in config must be defined.'),e(n.ix,"SDK Send Error: context.ix must be defined."),Promise.resolve(t).then(function(s){switch(t=s,!0){case n.ix.isTransaction(t):return o.sendTransaction?o.sendTransaction(t,n,o):ye(t,n,o);case n.ix.isGetTransactionStatus(t):return o.sendGetTransactionStatus?o.sendGetTransactionStatus(t,n,o):Se(t,n,o);case n.ix.isGetTransaction(t):return o.sendGetTransaction?o.sendGetTransaction(t,n,o):ge(t,n,o);case n.ix.isScript(t):return o.sendExecuteScript?o.sendExecuteScript(t,n,o):E(t,n,o);case n.ix.isGetAccount(t):return o.sendGetAccount?o.sendGetAccount(t,n,o):_(t,n,o);case n.ix.isGetEvents(t):return o.sendGetEvents?o.sendGetEvents(t,n,o):oe(t,n,o);case n.ix.isGetLatestBlock(t):return o.sendGetLatestBlock?o.sendGetLatestBlock(t,n,o):de(t,n,o);case n.ix.isGetBlock(t):return o.sendGetBlock?o.sendGetBlock(t,n,o):X(t,n,o);case n.ix.isGetBlockHeader(t):return o.sendGetBlockHeader?o.sendGetBlockHeader(t,n,o):O(t,n,o);case n.ix.isGetBlockById(t):return o.sendGetBlockById?o.sendGetBlockById(t,n,o):function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e(o.node,"SDK Send Get Block By ID Error: opts.node must be defined."),e(n.response,"SDK Send Get Block By ID Error: context.response must be defined."),e(n.Buffer,"SDK Send Get Block By ID Error: context.Buffer must be defined."),Promise.resolve(t).then(function(e){t=e;var s=new l;return s.setId(function(e,t){return t.Buffer.from(e,"hex")}(t.block.id,n)),Promise.resolve(x(o.node,r.GetBlockByID,s,n)).then(function(e){var r=e.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),i=r.getSignaturesList(),a=n.response();return a.tag=t.tag,a.block={id:Ge(r.getId_asU8(),n),parentId:Ge(r.getParentId_asU8(),n),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:Ge(e.getCollectionId_asU8(),n),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:Ge(e.getBlockId_asU8(),n),executionReceiptId:Ge(e.getExecutionReceiptId_asU8(),n),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}}(t,n,o);case n.ix.isGetBlockByHeight(t):return o.sendGetBlockByHeight?o.sendGetBlockByHeight(t,n,o):function(t,n,o){void 0===n&&(n={}),void 0===o&&(o={});try{return e(o.node,"SDK Send Get Block By Height Error: opts.node must be defined."),e(n.response,"SDK Send Get Block By Height Error: context.response must be defined."),e(n.Buffer,"SDK Send Get Block By Height Error: context.Buffer must be defined."),Promise.resolve(t).then(function(e){t=e;var s=new f;return s.setHeight(Number(t.block.height)),Promise.resolve(x(o.node,r.GetBlockByHeight,s,n)).then(function(e){var r=e.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),i=r.getSignaturesList(),a=n.response();return a.tag=t.tag,a.block={id:De(r.getId_asU8(),n),parentId:De(r.getParentId_asU8(),n),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:De(e.getCollectionId_asU8(),n),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:De(e.getBlockId_asU8(),n),executionReceiptId:De(e.getExecutionReceiptId_asU8(),n),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}}(t,n,o);case n.ix.isGetCollection(t):return o.sendGetCollection?o.sendGetCollection(t,n,o):te(t,n,o);case n.ix.isPing(t):return o.sendPing?o.sendPing(t,n,o):ke(t,n,o);default:return t}})}catch(e){return Promise.reject(e)}};export{Ae as send,E as sendExecuteScript,_ as sendGetAccount,X as sendGetBlock,O as sendGetBlockHeader,te as sendGetCollection,oe as sendGetEvents,de as sendGetLatestBlock,ge as sendGetTransaction,Se as sendGetTransactionStatus,ke as sendPing,ye as sendTransaction}; | ||
//# sourceMappingURL=sdk-send-grpc.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@onflow/util-invariant"),require("@onflow/protobuf"),require("@improbable-eng/grpc-web"),require("@improbable-eng/grpc-web-node-http-transport"),require("@onflow/util-address")):"function"==typeof define&&define.amd?define(["exports","@onflow/util-invariant","@onflow/protobuf","@improbable-eng/grpc-web","@improbable-eng/grpc-web-node-http-transport","@onflow/util-address"],t):t((e||self).transportGrpc={},e.utilInvariant,e.protobuf,e.grpcWeb,e.grpcWebNodeHttpTransport,e.utilAddress)}(this,function(e,t,n,r,o,s){var i=function(e,n,o,s){try{return t.invariant(s.config,"SDK GRPC Unary Error: context.config must be defined."),Promise.resolve(s.config().get("grpc.metadata",{})).then(function(t){return new Promise(function(s,i){r.grpc.unary(n,{request:o,host:e,metadata:new r.grpc.Metadata(t),onEnd:function(e){var t=e.statusMessage;e.status===r.grpc.Code.OK?s(e.message):i(new Error(t))}})})})}catch(e){return Promise.reject(e)}};r.grpc.setDefaultTransport(o.NodeHttpTransport());var a=function(e,n,r){void 0===n&&(n={}),void 0===r&&(r={});try{return t.invariant(r.node,"SDK Send Execute Script Error: opts.node must be defined."),t.invariant(n.response,"SDK Send Execute Script Error: context.response must be defined."),Promise.resolve(e).then(function(t){return e=t,Promise.resolve(e.block.id?d(e,n,r):e.block.height?u(e,n,r):c(e,n,r))})}catch(e){return Promise.reject(e)}},c=function(e,t,r){try{var o=r.unary||i,s=new n.ExecuteScriptAtLatestBlockRequest,a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return s.addArguments(l(e.arguments[t].asArgument))}),s.setScript(a),Promise.resolve(o(r.node,n.AccessAPI.ExecuteScriptAtLatestBlock,s,t)).then(function(n){return f(e,t,n)})}catch(e){return Promise.reject(e)}},u=function(e,t,r){try{var o=r.unary||i,s=new n.ExecuteScriptAtBlockHeightRequest;s.setBlockHeight(Number(e.block.height));var a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return s.addArguments(l(e.arguments[t].asArgument))}),s.setScript(a),Promise.resolve(o(r.node,n.AccessAPI.ExecuteScriptAtBlockHeight,s,t)).then(function(n){return f(e,t,n)})}catch(e){return Promise.reject(e)}},d=function(e,t,r){try{var o=r.unary||i,s=new n.ExecuteScriptAtBlockIDRequest;s.setBlockId(g(e.block.id));var a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return s.addArguments(l(e.arguments[t].asArgument))}),s.setScript(a),Promise.resolve(o(r.node,n.AccessAPI.ExecuteScriptAtBlockID,s,t)).then(function(n){return f(e,t,n)})}catch(e){return Promise.reject(e)}},l=function(e){return Buffer.from(JSON.stringify(e),"utf8")},g=function(e){return Buffer.from(e,"hex")};function f(e,t,n){var r=t.response();return r.tag=e.tag,r.encodedData=JSON.parse(Buffer.from(n.getValue_asU8()).toString("utf8")),r}function m(){return m=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},m.apply(this,arguments)}var p=function(e,n,r){void 0===n&&(n={}),void 0===r&&(r={});try{return t.invariant(r.node,"SDK Send Get Account Error: opts.node must be defined."),t.invariant(n.response,"SDK Get Account Error: context.response must be defined."),Promise.resolve(e).then(function(t){return e=t,Promise.resolve(null!==e.block.height?h(e,n,r):v(e,n,r))})}catch(e){return Promise.reject(e)}},v=function(e,t,r){try{var o=r.unary||i,a=new n.GetAccountAtLatestBlockRequest;return a.setAddress(B(s.sansPrefix(e.account.addr))),Promise.resolve(o(r.node,n.AccessAPI.GetAccountAtLatestBlock,a,t)).then(function(n){return y(e,t,n)})}catch(e){return Promise.reject(e)}},h=function(e,t,r){try{var o=r.unary||i,a=new n.GetAccountAtBlockHeightRequest;return a.setBlockHeight(Number(e.block.height)),a.setAddress(B(s.sansPrefix(e.account.addr))),Promise.resolve(o(r.node,n.AccessAPI.GetAccountAtBlockHeight,a,t)).then(function(n){return y(e,t,n)})}catch(e){return Promise.reject(e)}},S=function(e){return Buffer.from(e).toString("hex")},B=function(e){return Buffer.from(e.padStart(16,0),"hex")},k={1:"SHA2_256",2:"SHA2_384",3:"SHA3_256",4:"SHA3_384",5:"KMAC128_BLS_BLS12_381"},I={1:"ECDSA_P256",2:"ECDSA_secp256k1",3:"BLS_BLS12_381"};function y(e,t,n){var r=t.response();r.tag=e.tag;var o,i=n.getAccount(),a=(o=i.getContractsMap())?o.getEntryList().reduce(function(e,t){var n;return m({},e,((n={})[t[0]]=Buffer.from(t[1]||new UInt8Array).toString("utf8"),n))},{}):{};return r.account={address:s.withPrefix(S(i.getAddress_asU8())),balance:i.getBalance(),code:Buffer.from(i.getCode_asU8()||new UInt8Array).toString("utf8"),contracts:a,keys:i.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:S(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),signAlgoString:I[e.getSignAlgo()],hashAlgo:e.getHashAlgo(),hashAlgoString:k[e.getHashAlgo()],weight:e.getWeight(),sequenceNumber:e.getSequenceNumber(),revoked:e.getRevoked()}})},r}var P=function(e,n,r){void 0===n&&(n={}),void 0===r&&(r={});try{return t.invariant(r.node,"SDK Send Get Block Header Error: opts.node must be defined."),t.invariant(n.response,"SDK Send Get Block Header Error: context.response must be defined."),Promise.resolve(e).then(function(t){var o=null!==(e=t).block.height;return Promise.resolve(null!==e.block.id?G(e,n,r):o?A(e,n,r):b(e,n,r))})}catch(e){return Promise.reject(e)}},b=function(e,t,r){try{var o,s=r.unary||i,a=new n.GetLatestBlockHeaderRequest;return null!=(o=e.block)&&o.isSealed&&a.setIsSealed(e.block.isSealed),Promise.resolve(s(r.node,n.AccessAPI.GetLatestBlockHeader,a,t)).then(function(n){return L(e,t,n)})}catch(e){return Promise.reject(e)}},A=function(e,t,r){try{var o=r.unary||i,s=new n.GetBlockHeaderByHeightRequest;return s.setHeight(Number(e.block.height)),Promise.resolve(o(r.node,n.AccessAPI.GetBlockHeaderByHeight,s,t)).then(function(n){return L(e,t,n)})}catch(e){return Promise.reject(e)}},G=function(e,t,r){try{var o=r.unary||i,s=new n.GetBlockHeaderByIDRequest;return s.setId(E(e.block.id)),Promise.resolve(o(r.node,n.AccessAPI.GetBlockHeaderByID,s,t)).then(function(n){return L(e,t,n)})}catch(e){return Promise.reject(e)}},x=function(e){return Buffer.from(e).toString("hex")},E=function(e){return Buffer.from(e,"hex")};function L(e,t,n){var r=n.getBlock(),o=t.response();return o.tag=e.tag,o.blockHeader={id:x(r.getId_asU8()),parentId:x(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp().toDate().toISOString()},o}var w=function(e,n,r){void 0===n&&(n={}),void 0===r&&(r={});try{return t.invariant(r.node,"SDK Send Get Block Error: opts.node must be defined."),t.invariant(n.response,"SDK Send Get Block Error: context.response must be defined."),Promise.resolve(e).then(function(t){var o=null!==(e=t).block.height;return Promise.resolve(null!==e.block.id?H(e,n,r):o?T(e,n,r):D(e,n,r))})}catch(e){return Promise.reject(e)}},D=function(e,t,r){try{var o,s=r.unary||i,a=new n.GetLatestBlockRequest;return null!=(o=e.block)&&o.isSealed&&a.setIsSealed(e.block.isSealed),Promise.resolve(s(r.node,n.AccessAPI.GetLatestBlock,a,t)).then(function(n){return U(e,t,n)})}catch(e){return Promise.reject(e)}},T=function(e,t,r){try{var o=r.unary||i,s=new n.GetBlockByHeightRequest;return s.setHeight(Number(e.block.height)),Promise.resolve(o(r.node,n.AccessAPI.GetBlockByHeight,s,t)).then(function(n){return U(e,t,n)})}catch(e){return Promise.reject(e)}},H=function(e,t,r){try{var o=r.unary||i,s=new n.GetBlockByIDRequest;return s.setId(_(e.block.id)),Promise.resolve(o(r.node,n.AccessAPI.GetBlockByID,s,t)).then(function(n){return U(e,t,n)})}catch(e){return Promise.reject(e)}},R=function(e){return Buffer.from(e).toString("hex")},_=function(e){return Buffer.from(e,"hex")};function U(e,t,n){var r=n.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),i=r.getSignaturesList().map(R),a=t.response();return a.tag=e.tag,a.block={id:R(r.getId_asU8()),parentId:R(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp().toDate().toISOString(),collectionGuarantees:o.map(function(e){return{collectionId:R(e.getCollectionId_asU8()),signatures:e.getSignaturesList().map(R)}}),blockSeals:s.map(function(e){return{blockId:R(e.getBlockId_asU8()),executionReceiptId:R(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList().map(R),resultApprovalSignatures:e.getResultApprovalSignaturesList().map(R)}}),signatures:i},a}var K=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{t.invariant(o.node,"SDK Send Get Collection Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Get Collection Error: context.response must be defined.");var s=o.unary||i;return Promise.resolve(e).then(function(t){e=t;var i=new n.GetCollectionByIDRequest;return i.setId(q(e.collection.id)),Promise.resolve(s(o.node,n.AccessAPI.GetCollectionByID,i,r)).then(function(t){var n=t.getCollection(),o=r.response();return o.tag=e.tag,o.collection={id:j(n.getId_asU8()),transactionIds:n.getTransactionIdsList().map(j)},o})})}catch(e){return Promise.reject(e)}},j=function(e){return Buffer.from(e).toString("hex")},q=function(e){return Buffer.from(e,"hex")},N=function(e,n,r){void 0===n&&(n={}),void 0===r&&(r={});try{return t.invariant(r.node,"SDK Send Get Events Error: opts.node must be defined."),t.invariant(n.response,"SDK Send Get Events Error: context.response must be defined."),Promise.resolve(e).then(function(o){var s=null!==(e=o).events.start,i=Array.isArray(e.events.blockIds)&&e.events.blockIds.length>0;return t.invariant(s||i,"SendGetEventsError: Unable to determine which get events request to send. Either a block height range, or block IDs must be specified."),Promise.resolve(s?O(e,n,r):C(e,n,r))})}catch(e){return Promise.reject(e)}},C=function(e,t,r){try{var o=r.unary||i,s=new n.GetEventsForBlockIDsRequest;return s.setType(e.events.eventType),e.events.blockIds.forEach(function(e){return s.addBlockIds(J(e))}),Promise.resolve(o(r.node,n.AccessAPI.GetEventsForBlockIDs,s,t)).then(function(n){return M(e,t,n)})}catch(e){return Promise.reject(e)}},O=function(e,t,r){try{var o=r.unary||i,s=new n.GetEventsForHeightRangeRequest;return s.setType(e.events.eventType),s.setStartHeight(Number(e.events.start)),s.setEndHeight(Number(e.events.end)),Promise.resolve(o(r.node,n.AccessAPI.GetEventsForHeightRange,s,t)).then(function(n){return M(e,t,n)})}catch(e){return Promise.reject(e)}},F=function(e){return Buffer.from(e).toString("hex")},J=function(e){return Buffer.from(e,"hex")};function M(e,t,n){var r=t.response();r.tag=e.tag;var o=n.getResultsList();return r.events=o.reduce(function(e,t){var n=F(t.getBlockId_asU8()),r=t.getBlockHeight(),o=t.getBlockTimestamp().toDate().toISOString();return t.getEventsList().forEach(function(t){e.push({blockId:n,blockHeight:r,blockTimestamp:o,type:t.getType(),transactionId:F(t.getTransactionId_asU8()),transactionIndex:t.getTransactionIndex(),eventIndex:t.getEventIndex(),payload:JSON.parse(Buffer.from(t.getPayload_asU8()).toString("utf8"))})}),e},[]),r}var W=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{return t.invariant(o.node,"SDK Send Get Latest Block Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Get Latest Block Error: context.response must be defined."),Promise.resolve(e).then(function(t){e=t;var s=new n.GetLatestBlockRequest;return e.latestBlock&&e.latestBlock.isSealed&&(s.setIsSealed(e.latestBlock.isSealed),X()),e.block&&e.block.isSealed&&s.setIsSealed(e.block.isSealed),Promise.resolve(i(o.node,n.AccessAPI.GetLatestBlock,s,r)).then(function(t){var n=t.getBlock(),o=n.getCollectionGuaranteesList(),s=n.getBlockSealsList(),i=n.getSignaturesList(),a=r.response();return a.tag=e.tag,a.block={id:z(n.getId_asU8()),parentId:z(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:z(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:z(e.getBlockId_asU8()),executionReceiptId:z(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}},z=function(e){return Buffer.from(e).toString("hex")},X=function(){console.error("\n %c@onflow/send Deprecation Notice\n ========================\n\n Operating upon data of the latestBlock field of the interaction object is deprecated and will no longer be recognized in future releases of @onflow/send.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/send/WARNINGS.md#0001-Deprecating-latestBlock-field\n\n =======================\n ".replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")},V=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{t.invariant(o.node,"SDK Send Get Transaction Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Get Transaction Error: context.response must be defined.");var s=o.unary||i;return Promise.resolve(e).then(function(t){e=t;var i=new n.GetTransactionRequest;return i.setId(Q(e.transaction.id)),Promise.resolve(s(o.node,n.AccessAPI.GetTransaction,i,r)).then(function(t){var n=r.response();n.tag=e.tag;var o,s=function(e){return{address:Z(e.getAddress_asU8()),keyId:e.getKeyId(),signature:Z(e.getSignature_asU8())}},i=t.getTransaction();return n.transaction={script:Buffer.from(i.getScript_asU8()).toString("utf8"),args:i.getArgumentsList().map(function(e){return JSON.parse(Buffer.from(e).toString("utf8"))}),referenceBlockId:Z(i.getReferenceBlockId_asU8()),gasLimit:i.getGasLimit(),proposalKey:(o=i.getProposalKey(),{address:Z(o.getAddress_asU8()),keyId:o.getKeyId(),sequenceNumber:o.getSequenceNumber()}),payer:Z(i.getPayer_asU8()),authorizers:i.getAuthorizersList().map(Z),payloadSignatures:i.getPayloadSignaturesList().map(s),envelopeSignatures:i.getEnvelopeSignaturesList().map(s)},n})})}catch(e){return Promise.reject(e)}},Z=function(e){return Buffer.from(e).toString("hex")},Q=function(e){return Buffer.from(e,"hex")},Y=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{t.invariant(o.node,"SDK Send Get Transaction Status Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Get Transaction Status Error: context.response must be defined.");var s=o.unary||i;return Promise.resolve(e).then(function(t){e=t;var i=new n.GetTransactionRequest;return i.setId(te(e.transaction.id)),Promise.resolve(s(o.node,n.AccessAPI.GetTransactionResult,i,r)).then(function(t){var n=t.getEventsList(),o=r.response();return o.tag=e.tag,o.transactionStatus={status:t.getStatus(),statusString:$[t.getStatus()],statusCode:t.getStatusCode(),errorMessage:t.getErrorMessage(),events:n.map(function(e){return{type:e.getType(),transactionId:ee(e.getTransactionId_asU8()),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:JSON.parse(Buffer.from(e.getPayload_asU8()).toString("utf8"))}})},o})})}catch(e){return Promise.reject(e)}},$={0:"UNKNOWN",1:"PENDING",2:"FINALIZED",3:"EXECUTED",4:"SEALED",5:"EXPIRED"},ee=function(e){return Buffer.from(e).toString("hex")},te=function(e){return Buffer.from(e,"hex")},ne=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{t.invariant(o.node,"SDK Send Ping Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Ping Error: context.response must be defined.");var s=o.unary||i;return Promise.resolve(e).then(function(t){e=t;var i=new n.PingRequest;return Promise.resolve(s(o.node,n.AccessAPI.Ping,i,r)).then(function(t){var n=r.response();return n.tag=e.tag,n})})}catch(e){return Promise.reject(e)}},re=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{t.invariant(o.node,"SDK Send Transaction Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Transaction Error: context.response must be defined.");var a=o.unary||i;return Promise.resolve(e).then(function(t){e=t;var i=new n.Transaction;i.setScript(se(e.message.cadence)),i.setGasLimit(e.message.computeLimit),i.setReferenceBlockId(e.message.refBlock?ie(e.message.refBlock):null),i.setPayer(ae(s.sansPrefix(e.accounts[e.payer].addr))),e.message.arguments.forEach(function(t){return i.addArguments(ce(e.arguments[t].asArgument))}),e.authorizations.map(function(t){return e.accounts[t].addr}).reduce(function(e,t){return e.find(function(e){return e===t})?e:[].concat(e,[t])},[]).forEach(function(e){return i.addAuthorizers(ae(s.sansPrefix(e)))});var c=new n.Transaction.ProposalKey;c.setAddress(ae(s.sansPrefix(e.accounts[e.proposer].addr))),c.setKeyId(e.accounts[e.proposer].keyId),c.setSequenceNumber(e.accounts[e.proposer].sequenceNum),i.setProposalKey(c);for(var u=0,d=Object.values(e.accounts);u<d.length;u++){var l=d[u];try{if(!l.role.payer&&null!=l.signature){var g=new n.Transaction.Signature;g.setAddress(ae(s.sansPrefix(l.addr))),g.setKeyId(l.keyId),g.setSignature(ie(l.signature)),i.addPayloadSignatures(g)}}catch(t){throw console.error("Trouble applying payload signature",{acct:l,ix:e}),t}}for(var f=0,m=Object.values(e.accounts);f<m.length;f++){var p=m[f];try{if(p.role.payer&&null!=p.signature){var v=new n.Transaction.Signature;v.setAddress(ae(s.sansPrefix(p.addr))),v.setKeyId(p.keyId),v.setSignature(ie(p.signature)),i.addEnvelopeSignatures(v)}}catch(t){throw console.error("Trouble applying envelope signature",{acct:p,ix:e}),t}}var h=new n.SendTransactionRequest;h.setTransaction(i);var S=Date.now();return Promise.resolve(a(o.node,n.AccessAPI.SendTransaction,h,r)).then(function(t){var n=Date.now(),o=r.response();return o.tag=e.tag,o.transactionId=oe(t.getId_asU8()),"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("FLOW::TX",{detail:{txId:o.transactionId,delta:n-S}})),o})})}catch(e){return Promise.reject(e)}},oe=function(e){return Buffer.from(e).toString("hex")},se=function(e){return Buffer.from(e,"utf8")},ie=function(e){return Buffer.from(e,"hex")},ae=function(e){return Buffer.from(e.padStart(16,0),"hex")},ce=function(e){return Buffer.from(JSON.stringify(e),"utf8")},ue=function(e){return Buffer.from(e).toString("hex")},de=function(e){return Buffer.from(e).toString("hex")};e.send=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{return t.invariant(o.node,'SDK Send Error: Either opts.node or "accessNode.api" in config must be defined.'),t.invariant(r.ix,"SDK Send Error: context.ix must be defined."),Promise.resolve(e).then(function(s){switch(e=s,!0){case r.ix.isTransaction(e):return o.sendTransaction?o.sendTransaction(e,r,o):re(e,r,o);case r.ix.isGetTransactionStatus(e):return o.sendGetTransactionStatus?o.sendGetTransactionStatus(e,r,o):Y(e,r,o);case r.ix.isGetTransaction(e):return o.sendGetTransaction?o.sendGetTransaction(e,r,o):V(e,r,o);case r.ix.isScript(e):return o.sendExecuteScript?o.sendExecuteScript(e,r,o):a(e,r,o);case r.ix.isGetAccount(e):return o.sendGetAccount?o.sendGetAccount(e,r,o):p(e,r,o);case r.ix.isGetEvents(e):return o.sendGetEvents?o.sendGetEvents(e,r,o):N(e,r,o);case r.ix.isGetLatestBlock(e):return o.sendGetLatestBlock?o.sendGetLatestBlock(e,r,o):W(e,r,o);case r.ix.isGetBlock(e):return o.sendGetBlock?o.sendGetBlock(e,r,o):w(e,r,o);case r.ix.isGetBlockHeader(e):return o.sendGetBlockHeader?o.sendGetBlockHeader(e,r,o):P(e,r,o);case r.ix.isGetBlockById(e):return o.sendGetBlockById?o.sendGetBlockById(e,r,o):function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{return t.invariant(o.node,"SDK Send Get Block By ID Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Get Block By ID Error: context.response must be defined."),Promise.resolve(e).then(function(t){e=t;var s=new n.GetBlockByIDRequest;return s.setId(Buffer.from(e.block.id,"hex")),Promise.resolve(i(o.node,n.AccessAPI.GetBlockByID,s,r)).then(function(t){var n=t.getBlock(),o=n.getCollectionGuaranteesList(),s=n.getBlockSealsList(),i=n.getSignaturesList(),a=r.response();return a.tag=e.tag,a.block={id:ue(n.getId_asU8()),parentId:ue(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:ue(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:ue(e.getBlockId_asU8()),executionReceiptId:ue(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}}(e,r,o);case r.ix.isGetBlockByHeight(e):return o.sendGetBlockByHeight?o.sendGetBlockByHeight(e,r,o):function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{return t.invariant(o.node,"SDK Send Get Block By Height Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Get Block By Height Error: context.response must be defined."),Promise.resolve(e).then(function(t){e=t;var s=new n.GetBlockByHeightRequest;return s.setHeight(Number(e.block.height)),Promise.resolve(i(o.node,n.AccessAPI.GetBlockByHeight,s,r)).then(function(t){var n=t.getBlock(),o=n.getCollectionGuaranteesList(),s=n.getBlockSealsList(),i=n.getSignaturesList(),a=r.response();return a.tag=e.tag,a.block={id:de(n.getId_asU8()),parentId:de(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:de(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:de(e.getBlockId_asU8()),executionReceiptId:de(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}}(e,r,o);case r.ix.isGetCollection(e):return o.sendGetCollection?o.sendGetCollection(e,r,o):K(e,r,o);case r.ix.isPing(e):return o.sendPing?o.sendPing(e,r,o):ne(e,r,o);default:return e}})}catch(e){return Promise.reject(e)}},e.sendExecuteScript=a,e.sendGetAccount=p,e.sendGetBlock=w,e.sendGetBlockHeader=P,e.sendGetCollection=K,e.sendGetEvents=N,e.sendGetLatestBlock=W,e.sendGetTransaction=V,e.sendGetTransactionStatus=Y,e.sendPing=ne,e.sendTransaction=re}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@onflow/util-invariant"),require("@onflow/protobuf"),require("@improbable-eng/grpc-web"),require("@improbable-eng/grpc-web-node-http-transport"),require("@onflow/util-address")):"function"==typeof define&&define.amd?define(["exports","@onflow/util-invariant","@onflow/protobuf","@improbable-eng/grpc-web","@improbable-eng/grpc-web-node-http-transport","@onflow/util-address"],t):t((e||self).transportGrpc={},e.utilInvariant,e.protobuf,e.grpcWeb,e.grpcWebNodeHttpTransport,e.utilAddress)}(this,function(e,t,n,r,o,s){var i=function(e,n,o,s){try{return t.invariant(s.config,"SDK GRPC Unary Error: context.config must be defined."),Promise.resolve(s.config().get("grpc.metadata",{})).then(function(t){return new Promise(function(s,i){r.grpc.unary(n,{request:o,host:e,metadata:new r.grpc.Metadata(t),onEnd:function(e){var t=e.statusMessage;e.status===r.grpc.Code.OK?s(e.message):i(new Error(t))}})})})}catch(e){return Promise.reject(e)}};r.grpc.setDefaultTransport(o.NodeHttpTransport());var a=function(e,n,r){void 0===n&&(n={}),void 0===r&&(r={});try{return t.invariant(r.node,"SDK Send Execute Script Error: opts.node must be defined."),t.invariant(n.response,"SDK Send Execute Script Error: context.response must be defined."),t.invariant(n.Buffer,"SDK Send Execute Script Error: context.Buffer must be defined."),Promise.resolve(e).then(function(t){return e=t,Promise.resolve(e.block.id?d(e,n,r):e.block.height?u(e,n,r):c(e,n,r))})}catch(e){return Promise.reject(e)}},c=function(e,t,r){try{var o=r.unary||i,s=new n.ExecuteScriptAtLatestBlockRequest,a=t.Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(n){return s.addArguments(f(e.arguments[n].asArgument,t))}),s.setScript(a),Promise.resolve(o(r.node,n.AccessAPI.ExecuteScriptAtLatestBlock,s,t)).then(function(n){return g(e,t,n)})}catch(e){return Promise.reject(e)}},u=function(e,t,r){try{var o=r.unary||i,s=new n.ExecuteScriptAtBlockHeightRequest;s.setBlockHeight(Number(e.block.height));var a=t.Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(n){return s.addArguments(f(e.arguments[n].asArgument,t))}),s.setScript(a),Promise.resolve(o(r.node,n.AccessAPI.ExecuteScriptAtBlockHeight,s,t)).then(function(n){return g(e,t,n)})}catch(e){return Promise.reject(e)}},d=function(e,t,r){try{var o=r.unary||i,s=new n.ExecuteScriptAtBlockIDRequest;s.setBlockId(l(e.block.id,t));var a=t.Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(n){return s.addArguments(f(e.arguments[n].asArgument,t))}),s.setScript(a),Promise.resolve(o(r.node,n.AccessAPI.ExecuteScriptAtBlockID,s,t)).then(function(n){return g(e,t,n)})}catch(e){return Promise.reject(e)}},f=function(e,t){return t.Buffer.from(JSON.stringify(e),"utf8")},l=function(e,t){return t.Buffer.from(e,"hex")};function g(e,t,n){var r=t.response();return r.tag=e.tag,r.encodedData=JSON.parse(t.Buffer.from(n.getValue_asU8()).toString("utf8")),r}function m(){return m=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},m.apply(this,arguments)}var p=function(e,n,r){void 0===n&&(n={}),void 0===r&&(r={});try{return t.invariant(r.node,"SDK Send Get Account Error: opts.node must be defined."),t.invariant(n.response,"SDK Get Account Error: context.response must be defined."),t.invariant(n.Buffer,"SDK Get Account Error: context.Buffer must be defined."),Promise.resolve(e).then(function(t){return e=t,Promise.resolve(null!==e.block.height?S(e,n,r):v(e,n,r))})}catch(e){return Promise.reject(e)}},v=function(e,t,r){try{var o=r.unary||i,a=new n.GetAccountAtLatestBlockRequest;return a.setAddress(B(s.sansPrefix(e.account.addr),t)),Promise.resolve(o(r.node,n.AccessAPI.GetAccountAtLatestBlock,a,t)).then(function(n){return y(e,t,n)})}catch(e){return Promise.reject(e)}},S=function(e,t,r){try{var o=r.unary||i,a=new n.GetAccountAtBlockHeightRequest;return a.setBlockHeight(Number(e.block.height)),a.setAddress(B(s.sansPrefix(e.account.addr),t)),Promise.resolve(o(r.node,n.AccessAPI.GetAccountAtBlockHeight,a,t)).then(function(n){return y(e,t,n)})}catch(e){return Promise.reject(e)}},h=function(e,t){return t.Buffer.from(e).toString("hex")},B=function(e,t){return function(e,t,n){return n.Buffer.from(e.padStart(16,0),"hex")}(e,0,t)},k={1:"SHA2_256",2:"SHA2_384",3:"SHA3_256",4:"SHA3_384",5:"KMAC128_BLS_BLS12_381"},I={1:"ECDSA_P256",2:"ECDSA_secp256k1",3:"BLS_BLS12_381"};function y(e,t,n){var r=t.response();r.tag=e.tag;var o,i=n.getAccount(),a=(o=i.getContractsMap())?o.getEntryList().reduce(function(e,n){var r;return m({},e,((r={})[n[0]]=t.Buffer.from(n[1]||new UInt8Array).toString("utf8"),r))},{}):{};return r.account={address:s.withPrefix(h(i.getAddress_asU8(),t)),balance:i.getBalance(),code:t.Buffer.from(i.getCode_asU8()||new UInt8Array).toString("utf8"),contracts:a,keys:i.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:h(e.getPublicKey_asU8(),t),signAlgo:e.getSignAlgo(),signAlgoString:I[e.getSignAlgo()],hashAlgo:e.getHashAlgo(),hashAlgoString:k[e.getHashAlgo()],weight:e.getWeight(),sequenceNumber:e.getSequenceNumber(),revoked:e.getRevoked()}})},r}var b=function(e,n,r){void 0===n&&(n={}),void 0===r&&(r={});try{return t.invariant(r.node,"SDK Send Get Block Header Error: opts.node must be defined."),t.invariant(n.response,"SDK Send Get Block Header Error: context.response must be defined."),t.invariant(n.Buffer,"SDK Send Get Block Header Error: context.Buffer must be defined."),Promise.resolve(e).then(function(t){var o=null!==(e=t).block.height;return Promise.resolve(null!==e.block.id?A(e,n,r):o?x(e,n,r):P(e,n,r))})}catch(e){return Promise.reject(e)}},P=function(e,t,r){try{var o,s=r.unary||i,a=new n.GetLatestBlockHeaderRequest;return null!=(o=e.block)&&o.isSealed&&a.setIsSealed(e.block.isSealed),Promise.resolve(s(r.node,n.AccessAPI.GetLatestBlockHeader,a,t)).then(function(n){return D(e,t,n)})}catch(e){return Promise.reject(e)}},x=function(e,t,r){try{var o=r.unary||i,s=new n.GetBlockHeaderByHeightRequest;return s.setHeight(Number(e.block.height)),Promise.resolve(o(r.node,n.AccessAPI.GetBlockHeaderByHeight,s,t)).then(function(n){return D(e,t,n)})}catch(e){return Promise.reject(e)}},A=function(e,t,r){try{var o=r.unary||i,s=new n.GetBlockHeaderByIDRequest;return s.setId(E(e.block.id,t)),Promise.resolve(o(r.node,n.AccessAPI.GetBlockHeaderByID,s,t)).then(function(n){return D(e,t,n)})}catch(e){return Promise.reject(e)}},G=function(e,t){return t.Buffer.from(e).toString("hex")},E=function(e,t){return t.Buffer.from(e,"hex")};function D(e,t,n){var r=n.getBlock(),o=t.response();return o.tag=e.tag,o.blockHeader={id:G(r.getId_asU8(),t),parentId:G(r.getParentId_asU8(),t),height:r.getHeight(),timestamp:r.getTimestamp().toDate().toISOString()},o}var L=function(e,n,r){void 0===n&&(n={}),void 0===r&&(r={});try{return t.invariant(r.node,"SDK Send Get Block Error: opts.node must be defined."),t.invariant(n.response,"SDK Send Get Block Error: context.response must be defined."),t.invariant(n.Buffer,"SDK Send Get Block Error: context.Buffer must be defined."),Promise.resolve(e).then(function(t){var o=null!==(e=t).block.height;return Promise.resolve(null!==e.block.id?K(e,n,r):o?T(e,n,r):w(e,n,r))})}catch(e){return Promise.reject(e)}},w=function(e,t,r){try{var o,s=r.unary||i,a=new n.GetLatestBlockRequest;return null!=(o=e.block)&&o.isSealed&&a.setIsSealed(e.block.isSealed),Promise.resolve(s(r.node,n.AccessAPI.GetLatestBlock,a,t)).then(function(n){return _(e,t,n)})}catch(e){return Promise.reject(e)}},T=function(e,t,r){try{var o=r.unary||i,s=new n.GetBlockByHeightRequest;return s.setHeight(Number(e.block.height)),Promise.resolve(o(r.node,n.AccessAPI.GetBlockByHeight,s,t)).then(function(n){return _(e,t,n)})}catch(e){return Promise.reject(e)}},K=function(e,t,r){try{var o=r.unary||i,s=new n.GetBlockByIDRequest;return s.setId(R(e.block.id,t)),Promise.resolve(o(r.node,n.AccessAPI.GetBlockByID,s,t)).then(function(n){return _(e,t,n)})}catch(e){return Promise.reject(e)}},H=function(e,t){return t.Buffer.from(e).toString("hex")},R=function(e,t){return t.Buffer.from(e,"hex")};function _(e,t,n){var r=n.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),i=r.getSignaturesList().map(function(e){return H(e,t)}),a=t.response();return a.tag=e.tag,a.block={id:H(r.getId_asU8(),t),parentId:H(r.getParentId_asU8(),t),height:r.getHeight(),timestamp:r.getTimestamp().toDate().toISOString(),collectionGuarantees:o.map(function(e){return{collectionId:H(e.getCollectionId_asU8(),t),signatures:e.getSignaturesList().map(function(e){return H(e,t)})}}),blockSeals:s.map(function(e){return{blockId:H(e.getBlockId_asU8(),t),executionReceiptId:H(e.getExecutionReceiptId_asU8(),t),executionReceiptSignatures:e.getExecutionReceiptSignaturesList().map(function(e){return H(e,t)}),resultApprovalSignatures:e.getResultApprovalSignaturesList().map(function(e){return H(e,t)})}}),signatures:i},a}var U=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{t.invariant(o.node,"SDK Send Get Collection Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Get Collection Error: context.response must be defined."),t.invariant(r.Buffer,"SDK Send Get Collection Error: context.Buffer must be defined.");var s=o.unary||i;return Promise.resolve(e).then(function(t){e=t;var i=new n.GetCollectionByIDRequest;return i.setId(q(e.collection.id,r)),Promise.resolve(s(o.node,n.AccessAPI.GetCollectionByID,i,r)).then(function(t){var n=t.getCollection(),o=r.response();return o.tag=e.tag,o.collection={id:j(n.getId_asU8(),r),transactionIds:n.getTransactionIdsList().map(function(e){return j(e,r)})},o})})}catch(e){return Promise.reject(e)}},j=function(e,t){return t.Buffer.from(e).toString("hex")},q=function(e,t){return t.Buffer.from(e,"hex")},N=function(e,n,r){void 0===n&&(n={}),void 0===r&&(r={});try{return t.invariant(r.node,"SDK Send Get Events Error: opts.node must be defined."),t.invariant(n.response,"SDK Send Get Events Error: context.response must be defined."),t.invariant(n.Buffer,"SDK Send Get Events Error: context.Buffer must be defined."),Promise.resolve(e).then(function(o){var s=null!==(e=o).events.start,i=Array.isArray(e.events.blockIds)&&e.events.blockIds.length>0;return t.invariant(s||i,"SendGetEventsError: Unable to determine which get events request to send. Either a block height range, or block IDs must be specified."),Promise.resolve(s?O(e,n,r):C(e,n,r))})}catch(e){return Promise.reject(e)}},C=function(e,t,r){try{var o=r.unary||i,s=new n.GetEventsForBlockIDsRequest;return s.setType(e.events.eventType),e.events.blockIds.forEach(function(e){return s.addBlockIds(J(e,t))}),Promise.resolve(o(r.node,n.AccessAPI.GetEventsForBlockIDs,s,t)).then(function(n){return M(e,t,n)})}catch(e){return Promise.reject(e)}},O=function(e,t,r){try{var o=r.unary||i,s=new n.GetEventsForHeightRangeRequest;return s.setType(e.events.eventType),s.setStartHeight(Number(e.events.start)),s.setEndHeight(Number(e.events.end)),Promise.resolve(o(r.node,n.AccessAPI.GetEventsForHeightRange,s,t)).then(function(n){return M(e,t,n)})}catch(e){return Promise.reject(e)}},F=function(e,t){return t.Buffer.from(e).toString("hex")},J=function(e,t){return t.Buffer.from(e,"hex")};function M(e,t,n){var r=t.response();r.tag=e.tag;var o=n.getResultsList();return r.events=o.reduce(function(e,n){var r=F(n.getBlockId_asU8(),t),o=n.getBlockHeight(),s=n.getBlockTimestamp().toDate().toISOString();return n.getEventsList().forEach(function(n){e.push({blockId:r,blockHeight:o,blockTimestamp:s,type:n.getType(),transactionId:F(n.getTransactionId_asU8(),t),transactionIndex:n.getTransactionIndex(),eventIndex:n.getEventIndex(),payload:JSON.parse(t.Buffer.from(n.getPayload_asU8()).toString("utf8"))})}),e},[]),r}var W=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{return t.invariant(o.node,"SDK Send Get Latest Block Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Get Latest Block Error: context.response must be defined."),t.invariant(r.Buffer,"SDK Send Get Latest Block Error: context.Buffer must be defined."),Promise.resolve(e).then(function(t){e=t;var s=new n.GetLatestBlockRequest;return e.latestBlock&&e.latestBlock.isSealed&&(s.setIsSealed(e.latestBlock.isSealed),X()),e.block&&e.block.isSealed&&s.setIsSealed(e.block.isSealed),Promise.resolve(i(o.node,n.AccessAPI.GetLatestBlock,s,r)).then(function(t){var n=t.getBlock(),o=n.getCollectionGuaranteesList(),s=n.getBlockSealsList(),i=n.getSignaturesList(),a=r.response();return a.tag=e.tag,a.block={id:z(n.getId_asU8(),r),parentId:z(n.getParentId_asU8(),r),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:z(e.getCollectionId_asU8(),r),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:z(e.getBlockId_asU8(),r),executionReceiptId:z(e.getExecutionReceiptId_asU8(),r),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}},z=function(e,t){return t.Buffer.from(e).toString("hex")},X=function(){console.error("\n %c@onflow/send Deprecation Notice\n ========================\n\n Operating upon data of the latestBlock field of the interaction object is deprecated and will no longer be recognized in future releases of @onflow/send.\n Find out more here: https://github.com/onflow/flow-js-sdk/blob/master/packages/send/WARNINGS.md#0001-Deprecating-latestBlock-field\n\n =======================\n ".replace(/\n\s+/g,"\n").trim(),"font-weight:bold;font-family:monospace;")},V=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{t.invariant(o.node,"SDK Send Get Transaction Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Get Transaction Error: context.response must be defined."),t.invariant(r.Buffer,"SDK Send Get Transaction Error: context.Buffer must be defined.");var s=o.unary||i;return Promise.resolve(e).then(function(t){e=t;var i=new n.GetTransactionRequest;return i.setId(Q(e.transaction.id,r)),Promise.resolve(s(o.node,n.AccessAPI.GetTransaction,i,r)).then(function(t){var n=r.response();n.tag=e.tag;var o,s=function(e){return{address:Z(e.getAddress_asU8(),r),keyId:e.getKeyId(),signature:Z(e.getSignature_asU8(),r)}},i=t.getTransaction();return n.transaction={script:r.Buffer.from(i.getScript_asU8()).toString("utf8"),args:i.getArgumentsList().map(function(e){return JSON.parse(r.Buffer.from(e).toString("utf8"))}),referenceBlockId:Z(i.getReferenceBlockId_asU8(),r),gasLimit:i.getGasLimit(),proposalKey:(o=i.getProposalKey(),{address:Z(o.getAddress_asU8(),r),keyId:o.getKeyId(),sequenceNumber:o.getSequenceNumber()}),payer:Z(i.getPayer_asU8(),r),authorizers:i.getAuthorizersList().map(function(e){return Z(e,r)}),payloadSignatures:i.getPayloadSignaturesList().map(s),envelopeSignatures:i.getEnvelopeSignaturesList().map(s)},n})})}catch(e){return Promise.reject(e)}},Z=function(e,t){return t.Buffer.from(e).toString("hex")},Q=function(e,t){return t.Buffer.from(e,"hex")},Y=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{t.invariant(o.node,"SDK Send Get Transaction Status Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Get Transaction Status Error: context.response must be defined."),t.invariant(r.Buffer,"SDK Send Get Transaction Status Error: context.Buffer must be defined.");var s=o.unary||i;return Promise.resolve(e).then(function(t){e=t;var i=new n.GetTransactionRequest;return i.setId(te(e.transaction.id,r)),Promise.resolve(s(o.node,n.AccessAPI.GetTransactionResult,i,r)).then(function(t){var n=t.getEventsList(),o=r.response();return o.tag=e.tag,o.transactionStatus={status:t.getStatus(),statusString:$[t.getStatus()],statusCode:t.getStatusCode(),errorMessage:t.getErrorMessage(),events:n.map(function(e){return{type:e.getType(),transactionId:ee(e.getTransactionId_asU8(),r),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:JSON.parse(r.Buffer.from(e.getPayload_asU8()).toString("utf8"))}})},o})})}catch(e){return Promise.reject(e)}},$={0:"UNKNOWN",1:"PENDING",2:"FINALIZED",3:"EXECUTED",4:"SEALED",5:"EXPIRED"},ee=function(e,t){return t.Buffer.from(e).toString("hex")},te=function(e,t){return t.Buffer.from(e,"hex")},ne=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{t.invariant(o.node,"SDK Send Ping Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Ping Error: context.response must be defined.");var s=o.unary||i;return Promise.resolve(e).then(function(t){e=t;var i=new n.PingRequest;return Promise.resolve(s(o.node,n.AccessAPI.Ping,i,r)).then(function(t){var n=r.response();return n.tag=e.tag,n})})}catch(e){return Promise.reject(e)}},re=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{t.invariant(o.node,"SDK Send Transaction Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Transaction Error: context.response must be defined."),t.invariant(r.Buffer,"SDK Send Transaction Error: context.Buffer must be defined.");var a=o.unary||i;return Promise.resolve(e).then(function(t){e=t;var i=new n.Transaction;i.setScript(se(e.message.cadence,r)),i.setGasLimit(e.message.computeLimit),i.setReferenceBlockId(e.message.refBlock?ie(e.message.refBlock,r):null),i.setPayer(ae(s.sansPrefix(e.accounts[Array.isArray(e.payer)?e.payer[0]:e.payer].addr),r)),e.message.arguments.forEach(function(t){return i.addArguments(ce(e.arguments[t].asArgument,r))}),e.authorizations.map(function(t){return e.accounts[t].addr}).reduce(function(e,t){return e.find(function(e){return e===t})?e:[].concat(e,[t])},[]).forEach(function(e){return i.addAuthorizers(ae(s.sansPrefix(e),r))});var c=new n.Transaction.ProposalKey;c.setAddress(ae(s.sansPrefix(e.accounts[e.proposer].addr),r)),c.setKeyId(e.accounts[e.proposer].keyId),c.setSequenceNumber(e.accounts[e.proposer].sequenceNum),i.setProposalKey(c);for(var u=0,d=Object.values(e.accounts);u<d.length;u++){var f=d[u];try{if(!f.role.payer&&null!=f.signature){var l=new n.Transaction.Signature;l.setAddress(ae(s.sansPrefix(f.addr),r)),l.setKeyId(f.keyId),l.setSignature(ie(f.signature,r)),i.addPayloadSignatures(l)}}catch(t){throw console.error("Trouble applying payload signature",{acct:f,ix:e}),t}}for(var g=0,m=Object.values(e.accounts);g<m.length;g++){var p=m[g];try{if(p.role.payer&&null!=p.signature){var v=new n.Transaction.Signature;v.setAddress(ae(s.sansPrefix(p.addr),r)),v.setKeyId(p.keyId),v.setSignature(ie(p.signature,r)),i.addEnvelopeSignatures(v)}}catch(t){throw console.error("Trouble applying envelope signature",{acct:p,ix:e}),t}}var S=new n.SendTransactionRequest;S.setTransaction(i);var h=Date.now();return Promise.resolve(a(o.node,n.AccessAPI.SendTransaction,S,r)).then(function(t){var n=Date.now(),o=r.response();return o.tag=e.tag,o.transactionId=oe(t.getId_asU8(),r),"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("FLOW::TX",{detail:{txId:o.transactionId,delta:n-h}})),o})})}catch(e){return Promise.reject(e)}},oe=function(e,t){return t.Buffer.from(e).toString("hex")},se=function(e,t){return t.Buffer.from(e,"utf8")},ie=function(e,t){return t.Buffer.from(e,"hex")},ae=function(e,t){return function(e,t,n){return n.Buffer.from(e.padStart(16,0),"hex")}(e,0,t)},ce=function(e,t){return t.Buffer.from(JSON.stringify(e),"utf8")},ue=function(e,t){return t.Buffer.from(e).toString("hex")},de=function(e,t){return t.Buffer.from(e).toString("hex")};e.send=function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{return t.invariant(o.node,'SDK Send Error: Either opts.node or "accessNode.api" in config must be defined.'),t.invariant(r.ix,"SDK Send Error: context.ix must be defined."),Promise.resolve(e).then(function(s){switch(e=s,!0){case r.ix.isTransaction(e):return o.sendTransaction?o.sendTransaction(e,r,o):re(e,r,o);case r.ix.isGetTransactionStatus(e):return o.sendGetTransactionStatus?o.sendGetTransactionStatus(e,r,o):Y(e,r,o);case r.ix.isGetTransaction(e):return o.sendGetTransaction?o.sendGetTransaction(e,r,o):V(e,r,o);case r.ix.isScript(e):return o.sendExecuteScript?o.sendExecuteScript(e,r,o):a(e,r,o);case r.ix.isGetAccount(e):return o.sendGetAccount?o.sendGetAccount(e,r,o):p(e,r,o);case r.ix.isGetEvents(e):return o.sendGetEvents?o.sendGetEvents(e,r,o):N(e,r,o);case r.ix.isGetLatestBlock(e):return o.sendGetLatestBlock?o.sendGetLatestBlock(e,r,o):W(e,r,o);case r.ix.isGetBlock(e):return o.sendGetBlock?o.sendGetBlock(e,r,o):L(e,r,o);case r.ix.isGetBlockHeader(e):return o.sendGetBlockHeader?o.sendGetBlockHeader(e,r,o):b(e,r,o);case r.ix.isGetBlockById(e):return o.sendGetBlockById?o.sendGetBlockById(e,r,o):function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{return t.invariant(o.node,"SDK Send Get Block By ID Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Get Block By ID Error: context.response must be defined."),t.invariant(r.Buffer,"SDK Send Get Block By ID Error: context.Buffer must be defined."),Promise.resolve(e).then(function(t){e=t;var s=new n.GetBlockByIDRequest;return s.setId(function(e,t){return t.Buffer.from(e,"hex")}(e.block.id,r)),Promise.resolve(i(o.node,n.AccessAPI.GetBlockByID,s,r)).then(function(t){var n=t.getBlock(),o=n.getCollectionGuaranteesList(),s=n.getBlockSealsList(),i=n.getSignaturesList(),a=r.response();return a.tag=e.tag,a.block={id:ue(n.getId_asU8(),r),parentId:ue(n.getParentId_asU8(),r),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:ue(e.getCollectionId_asU8(),r),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:ue(e.getBlockId_asU8(),r),executionReceiptId:ue(e.getExecutionReceiptId_asU8(),r),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}}(e,r,o);case r.ix.isGetBlockByHeight(e):return o.sendGetBlockByHeight?o.sendGetBlockByHeight(e,r,o):function(e,r,o){void 0===r&&(r={}),void 0===o&&(o={});try{return t.invariant(o.node,"SDK Send Get Block By Height Error: opts.node must be defined."),t.invariant(r.response,"SDK Send Get Block By Height Error: context.response must be defined."),t.invariant(r.Buffer,"SDK Send Get Block By Height Error: context.Buffer must be defined."),Promise.resolve(e).then(function(t){e=t;var s=new n.GetBlockByHeightRequest;return s.setHeight(Number(e.block.height)),Promise.resolve(i(o.node,n.AccessAPI.GetBlockByHeight,s,r)).then(function(t){var n=t.getBlock(),o=n.getCollectionGuaranteesList(),s=n.getBlockSealsList(),i=n.getSignaturesList(),a=r.response();return a.tag=e.tag,a.block={id:de(n.getId_asU8(),r),parentId:de(n.getParentId_asU8(),r),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:de(e.getCollectionId_asU8(),r),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:de(e.getBlockId_asU8(),r),executionReceiptId:de(e.getExecutionReceiptId_asU8(),r),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:i},a})})}catch(e){return Promise.reject(e)}}(e,r,o);case r.ix.isGetCollection(e):return o.sendGetCollection?o.sendGetCollection(e,r,o):U(e,r,o);case r.ix.isPing(e):return o.sendPing?o.sendPing(e,r,o):ne(e,r,o);default:return e}})}catch(e){return Promise.reject(e)}},e.sendExecuteScript=a,e.sendGetAccount=p,e.sendGetBlock=L,e.sendGetBlockHeader=b,e.sendGetCollection=U,e.sendGetEvents=N,e.sendGetLatestBlock=W,e.sendGetTransaction=V,e.sendGetTransactionStatus=Y,e.sendPing=ne,e.sendTransaction=re}); | ||
//# sourceMappingURL=sdk-send-grpc.umd.js.map |
{ | ||
"name": "@onflow/transport-grpc", | ||
"version": "0.0.3-alpha.1", | ||
"version": "0.0.3-multisig.0", | ||
"description": "Flow SDK GRPC Transport Module", | ||
@@ -41,3 +41,3 @@ "license": "Apache-2.0", | ||
"@onflow/protobuf": "^0.1.8", | ||
"@onflow/rlp": "^0.0.3", | ||
"@onflow/rlp": "^0.0.4-multisig.0", | ||
"@onflow/util-address": "^0.0.0", | ||
@@ -47,3 +47,3 @@ "@onflow/util-invariant": "^0.0.0", | ||
}, | ||
"gitHead": "f843a85843363f14235447dbd5a3fc8468d571da" | ||
"gitHead": "d70efd556f875139bde813b261fa537c2c4f0717" | ||
} |
@@ -5,4 +5,4 @@ import {invariant} from "@onflow/util-invariant" | ||
const argumentBuffer = arg => Buffer.from(JSON.stringify(arg), "utf8") | ||
const hexBuffer = hex => Buffer.from(hex, "hex") | ||
const argumentBuffer = (arg, context) => context.Buffer.from(JSON.stringify(arg), "utf8") | ||
const hexBuffer = (hex, context) => context.Buffer.from(hex, "hex") | ||
@@ -14,6 +14,6 @@ async function sendExecuteScriptAtBlockIDRequest(ix, context, opts) { | ||
req.setBlockId(hexBuffer(ix.block.id)) | ||
req.setBlockId(hexBuffer(ix.block.id, context)) | ||
const code = Buffer.from(ix.message.cadence, "utf8") | ||
ix.message.arguments.forEach(arg => req.addArguments(argumentBuffer(ix.arguments[arg].asArgument))) | ||
const code = context.Buffer.from(ix.message.cadence, "utf8") | ||
ix.message.arguments.forEach(arg => req.addArguments(argumentBuffer(ix.arguments[arg].asArgument, context))) | ||
req.setScript(code) | ||
@@ -33,4 +33,4 @@ | ||
const code = Buffer.from(ix.message.cadence, "utf8") | ||
ix.message.arguments.forEach(arg => req.addArguments(argumentBuffer(ix.arguments[arg].asArgument))) | ||
const code = context.Buffer.from(ix.message.cadence, "utf8") | ||
ix.message.arguments.forEach(arg => req.addArguments(argumentBuffer(ix.arguments[arg].asArgument, context))) | ||
req.setScript(code) | ||
@@ -48,4 +48,4 @@ | ||
const code = Buffer.from(ix.message.cadence, "utf8") | ||
ix.message.arguments.forEach(arg => req.addArguments(argumentBuffer(ix.arguments[arg].asArgument))) | ||
const code = context.Buffer.from(ix.message.cadence, "utf8") | ||
ix.message.arguments.forEach(arg => req.addArguments(argumentBuffer(ix.arguments[arg].asArgument, context))) | ||
req.setScript(code) | ||
@@ -61,3 +61,3 @@ | ||
ret.tag = ix.tag | ||
ret.encodedData = JSON.parse(Buffer.from(res.getValue_asU8()).toString("utf8")) | ||
ret.encodedData = JSON.parse(context.Buffer.from(res.getValue_asU8()).toString("utf8")) | ||
@@ -70,2 +70,3 @@ return ret | ||
invariant(context.response, `SDK Send Execute Script Error: context.response must be defined.`) | ||
invariant(context.Buffer, `SDK Send Execute Script Error: context.Buffer must be defined.`) | ||
@@ -72,0 +73,0 @@ ix = await ix |
@@ -9,2 +9,3 @@ import {AccessAPI} from "@onflow/protobuf" | ||
import {response as responseADT} from "../../sdk/src/response/response.js" | ||
import {Buffer} from "@onflow/rlp" | ||
@@ -37,3 +38,4 @@ const jsonToUInt8Array = (json) => { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -81,3 +83,4 @@ { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -127,3 +130,4 @@ { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -130,0 +134,0 @@ { |
@@ -6,7 +6,7 @@ import {invariant} from "@onflow/util-invariant" | ||
const u8ToHex = u8 => Buffer.from(u8).toString("hex") | ||
const paddedHexBuffer = (hex, pad) => | ||
Buffer.from(hex.padStart(pad * 2, 0), "hex") | ||
const u8ToHex = (u8, context) => context.Buffer.from(u8).toString("hex") | ||
const paddedHexBuffer = (hex, pad, context) => | ||
context.Buffer.from(hex.padStart(pad * 2, 0), "hex") | ||
const addressBuffer = addr => paddedHexBuffer(addr, 8) | ||
const addressBuffer = (addr, context) => paddedHexBuffer(addr, 8, context) | ||
@@ -32,3 +32,3 @@ const HashAlgorithmNames = { | ||
req.setBlockHeight(Number(ix.block.height)) | ||
req.setAddress(addressBuffer(sansPrefix(ix.account.addr))) | ||
req.setAddress(addressBuffer(sansPrefix(ix.account.addr), context)) | ||
@@ -44,3 +44,3 @@ const res = await unary(opts.node, AccessAPI.GetAccountAtBlockHeight, req, context) | ||
const req = new GetAccountAtLatestBlockRequest() | ||
req.setAddress(addressBuffer(sansPrefix(ix.account.addr))) | ||
req.setAddress(addressBuffer(sansPrefix(ix.account.addr), context)) | ||
@@ -61,13 +61,13 @@ const res = await unary(opts.node, AccessAPI.GetAccountAtLatestBlock, req, context) | ||
...acc, | ||
[contract[0]]: Buffer.from(contract[1] || new UInt8Array()).toString("utf8") | ||
[contract[0]]: context.Buffer.from(contract[1] || new UInt8Array()).toString("utf8") | ||
}), {}) : {} | ||
ret.account = { | ||
address: withPrefix(u8ToHex(account.getAddress_asU8())), | ||
address: withPrefix(u8ToHex(account.getAddress_asU8(), context)), | ||
balance: account.getBalance(), | ||
code: Buffer.from(account.getCode_asU8() || new UInt8Array()).toString("utf8"), | ||
code: context.Buffer.from(account.getCode_asU8() || new UInt8Array()).toString("utf8"), | ||
contracts, | ||
keys: account.getKeysList().map(publicKey => ({ | ||
index: publicKey.getIndex(), | ||
publicKey: u8ToHex(publicKey.getPublicKey_asU8()), | ||
publicKey: u8ToHex(publicKey.getPublicKey_asU8(), context), | ||
signAlgo: publicKey.getSignAlgo(), | ||
@@ -90,2 +90,3 @@ signAlgoString: SignatureAlgorithmNames[publicKey.getSignAlgo()], // New! Verify this field name for correctness. | ||
invariant(context.response, `SDK Get Account Error: context.response must be defined.`) | ||
invariant(context.Buffer, `SDK Get Account Error: context.Buffer must be defined.`) | ||
@@ -92,0 +93,0 @@ ix = await ix |
@@ -8,2 +8,3 @@ import {AccessAPI} from "@onflow/protobuf" | ||
import {response as responseADT} from "../../sdk/src/response/response.js" | ||
import {Buffer} from "@onflow/rlp" | ||
@@ -63,3 +64,4 @@ const jsonToUInt8Array = (json) => { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -122,3 +124,4 @@ { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -125,0 +128,0 @@ { |
@@ -5,3 +5,3 @@ import {invariant} from "@onflow/util-invariant" | ||
const u8ToHex = u8 => Buffer.from(u8).toString("hex") | ||
const u8ToHex = (u8, context) => context.Buffer.from(u8).toString("hex") | ||
@@ -11,2 +11,3 @@ export async function sendGetBlockByHeight(ix, context = {}, opts = {}) { | ||
invariant(context.response, `SDK Send Get Block By Height Error: context.response must be defined.`) | ||
invariant(context.Buffer, `SDK Send Get Block By Height Error: context.Buffer must be defined.`) | ||
@@ -29,13 +30,13 @@ ix = await ix | ||
ret.block = { | ||
id: u8ToHex(block.getId_asU8()), | ||
parentId: u8ToHex(block.getParentId_asU8()), | ||
id: u8ToHex(block.getId_asU8(), context), | ||
parentId: u8ToHex(block.getParentId_asU8(), context), | ||
height: block.getHeight(), | ||
timestamp: block.getTimestamp(), | ||
collectionGuarantees: collectionGuarantees.map(collectionGuarantee => ({ | ||
collectionId: u8ToHex(collectionGuarantee.getCollectionId_asU8()), | ||
collectionId: u8ToHex(collectionGuarantee.getCollectionId_asU8(), context), | ||
signatures: collectionGuarantee.getSignaturesList(), | ||
})), | ||
blockSeals: blockSeals.map(blockSeal => ({ | ||
blockId: u8ToHex(blockSeal.getBlockId_asU8()), | ||
executionReceiptId: u8ToHex(blockSeal.getExecutionReceiptId_asU8()), | ||
blockId: u8ToHex(blockSeal.getBlockId_asU8(), context), | ||
executionReceiptId: u8ToHex(blockSeal.getExecutionReceiptId_asU8(), context), | ||
executionReceiptSignatures: blockSeal.getExecutionReceiptSignaturesList(), | ||
@@ -42,0 +43,0 @@ resultApprovalSignatures: blockSeal.getResultApprovalSignaturesList(), |
@@ -5,4 +5,4 @@ import {invariant} from "@onflow/util-invariant" | ||
const u8ToHex = u8 => Buffer.from(u8).toString("hex") | ||
const hexBuffer = hex => Buffer.from(hex, "hex") | ||
const u8ToHex = (u8, context) => context.Buffer.from(u8).toString("hex") | ||
const hexBuffer = (hex, context) => context.Buffer.from(hex, "hex") | ||
@@ -12,2 +12,3 @@ export async function sendGetBlockById(ix, context = {}, opts = {}) { | ||
invariant(context.response, `SDK Send Get Block By ID Error: context.response must be defined.`) | ||
invariant(context.Buffer, `SDK Send Get Block By ID Error: context.Buffer must be defined.`) | ||
@@ -17,3 +18,3 @@ ix = await ix | ||
const req = new GetBlockByIDRequest() | ||
req.setId(hexBuffer(ix.block.id)) | ||
req.setId(hexBuffer(ix.block.id, context)) | ||
@@ -31,13 +32,13 @@ const res = await unary(opts.node, AccessAPI.GetBlockByID, req, context) | ||
ret.block = { | ||
id: u8ToHex(block.getId_asU8()), | ||
parentId: u8ToHex(block.getParentId_asU8()), | ||
id: u8ToHex(block.getId_asU8(), context), | ||
parentId: u8ToHex(block.getParentId_asU8(), context), | ||
height: block.getHeight(), | ||
timestamp: block.getTimestamp(), | ||
collectionGuarantees: collectionGuarantees.map(collectionGuarantee => ({ | ||
collectionId: u8ToHex(collectionGuarantee.getCollectionId_asU8()), | ||
collectionId: u8ToHex(collectionGuarantee.getCollectionId_asU8(), context), | ||
signatures: collectionGuarantee.getSignaturesList(), | ||
})), | ||
blockSeals: blockSeals.map(blockSeal => ({ | ||
blockId: u8ToHex(blockSeal.getBlockId_asU8()), | ||
executionReceiptId: u8ToHex(blockSeal.getExecutionReceiptId_asU8()), | ||
blockId: u8ToHex(blockSeal.getBlockId_asU8(), context), | ||
executionReceiptId: u8ToHex(blockSeal.getExecutionReceiptId_asU8(), context), | ||
executionReceiptSignatures: blockSeal.getExecutionReceiptSignaturesList(), | ||
@@ -44,0 +45,0 @@ resultApprovalSignatures: blockSeal.getResultApprovalSignaturesList(), |
@@ -5,4 +5,4 @@ import {invariant} from "@onflow/util-invariant" | ||
const u8ToHex = u8 => Buffer.from(u8).toString("hex") | ||
const hexBuffer = hex => Buffer.from(hex, "hex") | ||
const u8ToHex = (u8, context) => context.Buffer.from(u8).toString("hex") | ||
const hexBuffer = (hex, context) => context.Buffer.from(hex, "hex") | ||
@@ -13,3 +13,3 @@ async function sendGetBlockHeaderByIDRequest(ix, context, opts) { | ||
const req = new GetBlockHeaderByIDRequest() | ||
req.setId(hexBuffer(ix.block.id)) | ||
req.setId(hexBuffer(ix.block.id, context)) | ||
@@ -52,4 +52,4 @@ const res = await unary(opts.node, AccessAPI.GetBlockHeaderByID, req, context) | ||
ret.blockHeader = { | ||
id: u8ToHex(blockHeader.getId_asU8()), | ||
parentId: u8ToHex(blockHeader.getParentId_asU8()), | ||
id: u8ToHex(blockHeader.getId_asU8(), context), | ||
parentId: u8ToHex(blockHeader.getParentId_asU8(), context), | ||
height: blockHeader.getHeight(), | ||
@@ -65,2 +65,3 @@ timestamp: blockHeader.getTimestamp().toDate().toISOString(), | ||
invariant(context.response, `SDK Send Get Block Header Error: context.response must be defined.`) | ||
invariant(context.Buffer, `SDK Send Get Block Header Error: context.Buffer must be defined.`) | ||
@@ -67,0 +68,0 @@ ix = await ix |
@@ -9,2 +9,3 @@ import {AccessAPI} from "@onflow/protobuf" | ||
import {response as responseADT} from "../../sdk/src/response/response.js" | ||
import {Buffer} from "@onflow/rlp" | ||
@@ -64,3 +65,4 @@ const jsonToUInt8Array = (json) => { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -122,3 +124,4 @@ { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -179,3 +182,4 @@ { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -236,3 +240,4 @@ { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -239,0 +244,0 @@ { |
@@ -5,4 +5,4 @@ import {invariant} from "@onflow/util-invariant" | ||
const u8ToHex = u8 => Buffer.from(u8).toString("hex") | ||
const hexBuffer = hex => Buffer.from(hex, "hex") | ||
const u8ToHex = (u8, context) => context.Buffer.from(u8).toString("hex") | ||
const hexBuffer = (hex, context) => context.Buffer.from(hex, "hex") | ||
@@ -13,3 +13,3 @@ async function sendGetBlockByIDRequest(ix, context, opts) { | ||
const req = new GetBlockByIDRequest() | ||
req.setId(hexBuffer(ix.block.id)) | ||
req.setId(hexBuffer(ix.block.id, context)) | ||
@@ -51,3 +51,3 @@ const res = await unary(opts.node, AccessAPI.GetBlockByID, req, context) | ||
const blockSeals = block.getBlockSealsList() | ||
const signatures = (block.getSignaturesList()).map(u8ToHex) | ||
const signatures = (block.getSignaturesList()).map(sig => u8ToHex(sig, context)) | ||
@@ -57,15 +57,15 @@ const ret = context.response() | ||
ret.block = { | ||
id: u8ToHex(block.getId_asU8()), | ||
parentId: u8ToHex(block.getParentId_asU8()), | ||
id: u8ToHex(block.getId_asU8(), context), | ||
parentId: u8ToHex(block.getParentId_asU8(), context), | ||
height: block.getHeight(), | ||
timestamp: block.getTimestamp().toDate().toISOString(), | ||
collectionGuarantees: collectionGuarantees.map(collectionGuarantee => ({ | ||
collectionId: u8ToHex(collectionGuarantee.getCollectionId_asU8()), | ||
signatures: (collectionGuarantee.getSignaturesList()).map(u8ToHex), | ||
collectionId: u8ToHex(collectionGuarantee.getCollectionId_asU8(), context), | ||
signatures: (collectionGuarantee.getSignaturesList()).map(x => u8ToHex(x, context)), | ||
})), | ||
blockSeals: blockSeals.map(blockSeal => ({ | ||
blockId: u8ToHex(blockSeal.getBlockId_asU8()), | ||
executionReceiptId: u8ToHex(blockSeal.getExecutionReceiptId_asU8()), | ||
executionReceiptSignatures: (blockSeal.getExecutionReceiptSignaturesList()).map(u8ToHex), | ||
resultApprovalSignatures: (blockSeal.getResultApprovalSignaturesList()).map(u8ToHex), | ||
blockId: u8ToHex(blockSeal.getBlockId_asU8(), context), | ||
executionReceiptId: u8ToHex(blockSeal.getExecutionReceiptId_asU8(), context), | ||
executionReceiptSignatures: (blockSeal.getExecutionReceiptSignaturesList()).map(x => u8ToHex(x, context)), | ||
resultApprovalSignatures: (blockSeal.getResultApprovalSignaturesList()).map(x => u8ToHex(x, context)), | ||
})), | ||
@@ -81,2 +81,3 @@ signatures: signatures, | ||
invariant(context.response, `SDK Send Get Block Error: context.response must be defined.`) | ||
invariant(context.Buffer, `SDK Send Get Block Error: context.Buffer must be defined.`) | ||
@@ -83,0 +84,0 @@ ix = await ix |
@@ -9,2 +9,3 @@ import {AccessAPI} from "@onflow/protobuf" | ||
import {response as responseADT} from "../../sdk/src/response/response.js" | ||
import {Buffer} from "@onflow/rlp" | ||
@@ -72,3 +73,4 @@ const jsonToUInt8Array = (json) => { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -138,3 +140,4 @@ { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -203,3 +206,4 @@ { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -268,3 +272,4 @@ { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -271,0 +276,0 @@ { |
@@ -5,4 +5,4 @@ import {invariant} from "@onflow/util-invariant" | ||
const u8ToHex = u8 => Buffer.from(u8).toString("hex") | ||
const hexBuffer = hex => Buffer.from(hex, "hex") | ||
const u8ToHex = (u8, context) => context.Buffer.from(u8).toString("hex") | ||
const hexBuffer = (hex, context) => context.Buffer.from(hex, "hex") | ||
@@ -12,2 +12,3 @@ export async function sendGetCollection(ix, context = {}, opts = {}) { | ||
invariant(context.response, `SDK Send Get Collection Error: context.response must be defined.`) | ||
invariant(context.Buffer, `SDK Send Get Collection Error: context.Buffer must be defined.`) | ||
@@ -19,3 +20,3 @@ const unary = opts.unary || defaultUnary | ||
const req = new GetCollectionByIDRequest() | ||
req.setId(hexBuffer(ix.collection.id)) | ||
req.setId(hexBuffer(ix.collection.id, context)) | ||
@@ -29,4 +30,4 @@ const res = await unary(opts.node, AccessAPI.GetCollectionByID, req, context) | ||
ret.collection = { | ||
id: u8ToHex(collection.getId_asU8()), | ||
transactionIds: (collection.getTransactionIdsList()).map(u8ToHex) | ||
id: u8ToHex(collection.getId_asU8(), context), | ||
transactionIds: (collection.getTransactionIdsList()).map(x => u8ToHex(x, context)) | ||
} | ||
@@ -33,0 +34,0 @@ |
@@ -7,2 +7,3 @@ import {AccessAPI} from "@onflow/protobuf" | ||
import {response as responseADT} from "../../sdk/src/response/response.js" | ||
import {Buffer} from "@onflow/rlp" | ||
@@ -56,3 +57,4 @@ const jsonToUInt8Array = (json) => { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -59,0 +61,0 @@ { |
@@ -5,4 +5,4 @@ import {invariant} from "@onflow/util-invariant" | ||
const u8ToHex = u8 => Buffer.from(u8).toString("hex") | ||
const hexBuffer = hex => Buffer.from(hex, "hex") | ||
const u8ToHex = (u8, context) => context.Buffer.from(u8).toString("hex") | ||
const hexBuffer = (hex, context) => context.Buffer.from(hex, "hex") | ||
@@ -30,3 +30,3 @@ async function sendGetEventsForHeightRangeRequest(ix, context, opts) { | ||
ix.events.blockIds.forEach(id => | ||
req.addBlockIds(hexBuffer(id)) | ||
req.addBlockIds(hexBuffer(id, context)) | ||
) | ||
@@ -45,3 +45,3 @@ | ||
ret.events = results.reduce((blocks, result) => { | ||
const blockId = u8ToHex(result.getBlockId_asU8()) | ||
const blockId = u8ToHex(result.getBlockId_asU8(), context) | ||
const blockHeight = result.getBlockHeight() | ||
@@ -56,6 +56,6 @@ const blockTimestamp = result.getBlockTimestamp().toDate().toISOString() | ||
type: event.getType(), | ||
transactionId: u8ToHex(event.getTransactionId_asU8()), | ||
transactionId: u8ToHex(event.getTransactionId_asU8(), context), | ||
transactionIndex: event.getTransactionIndex(), | ||
eventIndex: event.getEventIndex(), | ||
payload: JSON.parse(Buffer.from(event.getPayload_asU8()).toString("utf8")), | ||
payload: JSON.parse(context.Buffer.from(event.getPayload_asU8()).toString("utf8")), | ||
}) | ||
@@ -72,2 +72,3 @@ }) | ||
invariant(context.response, `SDK Send Get Events Error: context.response must be defined.`) | ||
invariant(context.Buffer, `SDK Send Get Events Error: context.Buffer must be defined.`) | ||
@@ -74,0 +75,0 @@ ix = await ix |
@@ -9,2 +9,3 @@ import {AccessAPI} from "@onflow/protobuf" | ||
import {response as responseADT} from "../../sdk/src/response/response.js" | ||
import {Buffer} from "@onflow/rlp" | ||
@@ -81,3 +82,4 @@ const jsonToUInt8Array = (json) => { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -159,3 +161,4 @@ { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -162,0 +165,0 @@ { |
@@ -5,3 +5,3 @@ import {invariant} from "@onflow/util-invariant" | ||
const u8ToHex = u8 => Buffer.from(u8).toString("hex") | ||
const u8ToHex = (u8, context) => context.Buffer.from(u8).toString("hex") | ||
@@ -28,2 +28,3 @@ const latestBlockDeprecationNotice = () => { | ||
invariant(context.response, `SDK Send Get Latest Block Error: context.response must be defined.`) | ||
invariant(context.Buffer, `SDK Send Get Latest Block Error: context.Buffer must be defined.`) | ||
@@ -54,13 +55,13 @@ ix = await ix | ||
ret.block = { | ||
id: u8ToHex(block.getId_asU8()), | ||
parentId: u8ToHex(block.getParentId_asU8()), | ||
id: u8ToHex(block.getId_asU8(), context), | ||
parentId: u8ToHex(block.getParentId_asU8(), context), | ||
height: block.getHeight(), | ||
timestamp: block.getTimestamp(), | ||
collectionGuarantees: collectionGuarantees.map(collectionGuarantee => ({ | ||
collectionId: u8ToHex(collectionGuarantee.getCollectionId_asU8()), | ||
collectionId: u8ToHex(collectionGuarantee.getCollectionId_asU8(), context), | ||
signatures: collectionGuarantee.getSignaturesList(), | ||
})), | ||
blockSeals: blockSeals.map(blockSeal => ({ | ||
blockId: u8ToHex(blockSeal.getBlockId_asU8()), | ||
executionReceiptId: u8ToHex(blockSeal.getExecutionReceiptId_asU8()), | ||
blockId: u8ToHex(blockSeal.getBlockId_asU8(), context), | ||
executionReceiptId: u8ToHex(blockSeal.getExecutionReceiptId_asU8(), context), | ||
executionReceiptSignatures: blockSeal.getExecutionReceiptSignaturesList(), | ||
@@ -67,0 +68,0 @@ resultApprovalSignatures: blockSeal.getResultApprovalSignaturesList(), |
@@ -14,4 +14,4 @@ import {invariant} from "@onflow/util-invariant" | ||
const u8ToHex = u8 => Buffer.from(u8).toString("hex") | ||
const hexBuffer = hex => Buffer.from(hex, "hex") | ||
const u8ToHex = (u8, context) => context.Buffer.from(u8).toString("hex") | ||
const hexBuffer = (hex, context) => context.Buffer.from(hex, "hex") | ||
@@ -21,2 +21,3 @@ export async function sendGetTransactionStatus(ix, context = {}, opts = {}) { | ||
invariant(context.response, `SDK Send Get Transaction Status Error: context.response must be defined.`) | ||
invariant(context.Buffer, `SDK Send Get Transaction Status Error: context.Buffer must be defined.`) | ||
@@ -28,3 +29,3 @@ const unary = opts.unary || defaultUnary | ||
const req = new GetTransactionRequest() | ||
req.setId(hexBuffer(ix.transaction.id)) | ||
req.setId(hexBuffer(ix.transaction.id, context)) | ||
@@ -44,6 +45,6 @@ const res = await unary(opts.node, AccessAPI.GetTransactionResult, req, context) | ||
type: event.getType(), | ||
transactionId: u8ToHex(event.getTransactionId_asU8()), | ||
transactionId: u8ToHex(event.getTransactionId_asU8(), context), | ||
transactionIndex: event.getTransactionIndex(), | ||
eventIndex: event.getEventIndex(), | ||
payload: JSON.parse(Buffer.from(event.getPayload_asU8()).toString("utf8")), | ||
payload: JSON.parse(context.Buffer.from(event.getPayload_asU8()).toString("utf8")), | ||
})), | ||
@@ -50,0 +51,0 @@ } |
@@ -7,2 +7,3 @@ import {AccessAPI} from "@onflow/protobuf" | ||
import {response as responseADT} from "../../sdk/src/response/response.js" | ||
import {Buffer} from "@onflow/rlp" | ||
@@ -72,3 +73,4 @@ const jsonToUInt8Array = (json) => { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -75,0 +77,0 @@ { |
@@ -5,4 +5,4 @@ import {invariant} from "@onflow/util-invariant" | ||
const u8ToHex = u8 => Buffer.from(u8).toString("hex") | ||
const hexBuffer = hex => Buffer.from(hex, "hex") | ||
const u8ToHex = (u8, context) => context.Buffer.from(u8).toString("hex") | ||
const hexBuffer = (hex, context) => context.Buffer.from(hex, "hex") | ||
@@ -12,2 +12,3 @@ export async function sendGetTransaction(ix, context = {}, opts = {}) { | ||
invariant(context.response, `SDK Send Get Transaction Error: context.response must be defined.`) | ||
invariant(context.Buffer, `SDK Send Get Transaction Error: context.Buffer must be defined.`) | ||
@@ -19,3 +20,3 @@ const unary = opts.unary || defaultUnary | ||
const req = new GetTransactionRequest() | ||
req.setId(hexBuffer(ix.transaction.id)) | ||
req.setId(hexBuffer(ix.transaction.id, context)) | ||
@@ -28,3 +29,3 @@ const res = await unary(opts.node, AccessAPI.GetTransaction, req, context) | ||
const unwrapKey = key => ({ | ||
address: u8ToHex(key.getAddress_asU8()), | ||
address: u8ToHex(key.getAddress_asU8(), context), | ||
keyId: key.getKeyId(), | ||
@@ -35,5 +36,5 @@ sequenceNumber: key.getSequenceNumber() | ||
const unwrapSignature = sig => ({ | ||
address: u8ToHex(sig.getAddress_asU8()), | ||
address: u8ToHex(sig.getAddress_asU8(), context), | ||
keyId: sig.getKeyId(), | ||
signature: u8ToHex(sig.getSignature_asU8()) | ||
signature: u8ToHex(sig.getSignature_asU8(), context) | ||
}) | ||
@@ -43,9 +44,9 @@ | ||
ret.transaction = { | ||
script: Buffer.from(transaction.getScript_asU8()).toString("utf8"), | ||
args: (transaction.getArgumentsList()).map(arg => JSON.parse(Buffer.from(arg).toString("utf8"))), | ||
referenceBlockId: u8ToHex(transaction.getReferenceBlockId_asU8()), | ||
script: context.Buffer.from(transaction.getScript_asU8()).toString("utf8"), | ||
args: (transaction.getArgumentsList()).map(arg => JSON.parse(context.Buffer.from(arg).toString("utf8"))), | ||
referenceBlockId: u8ToHex(transaction.getReferenceBlockId_asU8(), context), | ||
gasLimit: transaction.getGasLimit(), | ||
proposalKey: unwrapKey(transaction.getProposalKey()), | ||
payer: u8ToHex(transaction.getPayer_asU8()), | ||
authorizers: (transaction.getAuthorizersList()).map(u8ToHex), | ||
payer: u8ToHex(transaction.getPayer_asU8(), context), | ||
authorizers: (transaction.getAuthorizersList()).map(x => u8ToHex(x, context)), | ||
payloadSignatures: (transaction.getPayloadSignaturesList()).map(unwrapSignature), | ||
@@ -52,0 +53,0 @@ envelopeSignatures: (transaction.getEnvelopeSignaturesList()).map(unwrapSignature) |
@@ -7,2 +7,3 @@ import {AccessAPI} from "@onflow/protobuf" | ||
import {response as responseADT} from "../../sdk/src/response/response.js" | ||
import {Buffer} from "@onflow/rlp" | ||
@@ -76,3 +77,4 @@ const jsonToUInt8Array = (json) => { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -79,0 +81,0 @@ { |
@@ -7,2 +7,3 @@ import {AccessAPI} from "@onflow/protobuf" | ||
import {response as responseADT} from "../../sdk/src/response/response.js" | ||
import {Buffer} from "@onflow/rlp" | ||
@@ -31,3 +32,4 @@ const jsonToUInt8Array = (json) => { | ||
{ | ||
response: responseADT | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -34,0 +36,0 @@ { |
@@ -6,9 +6,9 @@ import {invariant} from "@onflow/util-invariant" | ||
const u8ToHex = u8 => Buffer.from(u8).toString("hex") | ||
const paddedHexBuffer = (hex, pad) => | ||
Buffer.from(hex.padStart(pad * 2, 0), "hex") | ||
const scriptBuffer = script => Buffer.from(script, "utf8") | ||
const hexBuffer = hex => Buffer.from(hex, "hex") | ||
const addressBuffer = addr => paddedHexBuffer(addr, 8) | ||
const argumentBuffer = arg => Buffer.from(JSON.stringify(arg), "utf8") | ||
const u8ToHex = (u8, context) => context.Buffer.from(u8).toString("hex") | ||
const paddedHexBuffer = (hex, pad, context) => | ||
context.Buffer.from(hex.padStart(pad * 2, 0), "hex") | ||
const scriptBuffer = (script, context) => context.Buffer.from(script, "utf8") | ||
const hexBuffer = (hex, context) => context.Buffer.from(hex, "hex") | ||
const addressBuffer = (addr, context) => paddedHexBuffer(addr, 8, context) | ||
const argumentBuffer = (arg, context) => context.Buffer.from(JSON.stringify(arg), "utf8") | ||
@@ -18,2 +18,3 @@ export async function sendTransaction(ix, context = {}, opts = {}) { | ||
invariant(context.response, `SDK Send Transaction Error: context.response must be defined.`) | ||
invariant(context.Buffer, `SDK Send Transaction Error: context.Buffer must be defined.`) | ||
@@ -25,10 +26,11 @@ const unary = opts.unary || defaultUnary | ||
const tx = new Transaction() | ||
tx.setScript(scriptBuffer(ix.message.cadence)) | ||
tx.setScript(scriptBuffer(ix.message.cadence, context)) | ||
tx.setGasLimit(ix.message.computeLimit) | ||
tx.setReferenceBlockId( | ||
ix.message.refBlock ? hexBuffer(ix.message.refBlock) : null | ||
ix.message.refBlock ? hexBuffer(ix.message.refBlock, context) : null | ||
) | ||
tx.setPayer(addressBuffer(sansPrefix(ix.accounts[ix.payer].addr))) | ||
tx.setPayer(addressBuffer(sansPrefix(ix.accounts[Array.isArray(ix.payer) ? ix.payer[0] : ix.payer].addr), context)) | ||
ix.message.arguments.forEach(arg => | ||
tx.addArguments(argumentBuffer(ix.arguments[arg].asArgument)) | ||
tx.addArguments(argumentBuffer(ix.arguments[arg].asArgument, context)) | ||
) | ||
@@ -40,7 +42,7 @@ ix.authorizations | ||
}, []) | ||
.forEach(addr => tx.addAuthorizers(addressBuffer(sansPrefix(addr)))) | ||
.forEach(addr => tx.addAuthorizers(addressBuffer(sansPrefix(addr), context))) | ||
const proposalKey = new Transaction.ProposalKey() | ||
proposalKey.setAddress( | ||
addressBuffer(sansPrefix(ix.accounts[ix.proposer].addr)) | ||
addressBuffer(sansPrefix(ix.accounts[ix.proposer].addr), context) | ||
) | ||
@@ -57,5 +59,5 @@ proposalKey.setKeyId(ix.accounts[ix.proposer].keyId) | ||
const sig = new Transaction.Signature() | ||
sig.setAddress(addressBuffer(sansPrefix(acct.addr))) | ||
sig.setAddress(addressBuffer(sansPrefix(acct.addr), context)) | ||
sig.setKeyId(acct.keyId) | ||
sig.setSignature(hexBuffer(acct.signature)) | ||
sig.setSignature(hexBuffer(acct.signature, context)) | ||
tx.addPayloadSignatures(sig) | ||
@@ -74,5 +76,5 @@ } | ||
const sig = new Transaction.Signature() | ||
sig.setAddress(addressBuffer(sansPrefix(acct.addr))) | ||
sig.setAddress(addressBuffer(sansPrefix(acct.addr), context)) | ||
sig.setKeyId(acct.keyId) | ||
sig.setSignature(hexBuffer(acct.signature)) | ||
sig.setSignature(hexBuffer(acct.signature, context)) | ||
tx.addEnvelopeSignatures(sig) | ||
@@ -95,3 +97,3 @@ } | ||
ret.tag = ix.tag | ||
ret.transactionId = u8ToHex(res.getId_asU8()) | ||
ret.transactionId = u8ToHex(res.getId_asU8(), context) | ||
@@ -98,0 +100,0 @@ if (typeof window !== "undefined") { |
@@ -13,2 +13,3 @@ import {AccessAPI} from "@onflow/protobuf" | ||
import {response as responseADT} from "../../sdk/src/response/response.js" | ||
import {Buffer} from "@onflow/rlp" | ||
@@ -111,2 +112,3 @@ const jsonToUInt8Array = json => { | ||
response: responseADT, | ||
Buffer, | ||
}, | ||
@@ -113,0 +115,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
422362
2313
+ Added@onflow/rlp@0.0.4-multisig.0(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedieee754@1.2.1(transitive)
- Removed@onflow/rlp@0.0.3(transitive)