Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@onflow/send

Package Overview
Dependencies
Maintainers
8
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@onflow/send - npm Package Compare versions

Comparing version 0.0.24 to 0.0.25

2

CHANGELOG.md

@@ -5,3 +5,3 @@ ### Unreleased

### 0.0.[23..24] - 2020-12-03
### 0.0.[23..25] - 2020-12-03

@@ -8,0 +8,0 @@ - 2020-12-03 -- FIX modified how tx signatures were applied to gRPC call.

@@ -1,2 +0,2 @@

var e=require("@onflow/interaction"),t=require("@onflow/protobuf"),r=require("@onflow/response"),n=require("@onflow/util-address"),s=require("@improbable-eng/grpc-web"),o=require("@improbable-eng/grpc-web-node-http-transport"),a=require("@onflow/config"),i=function(e,t,r){try{return Promise.resolve(new Promise(function(n,o){s.grpc.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===s.grpc.Code.OK?n(e.message):o(new Error(t))}})}))}catch(e){return Promise.reject(e)}};s.grpc.setDefaultTransport(o.NodeHttpTransport());var c=function(e){return Buffer.from(e,"hex")},u=function(e){return Buffer.from(e.padStart(16,0),"hex")},g=function(e){return Buffer.from(e).toString("hex")},l=function(e){return Buffer.from(e).toString("hex")},d=function(e){return Buffer.from(e).toString("hex")},f=function(e){return Buffer.from(e).toString("hex")};exports.send=function(s,o){void 0===o&&(o={});try{var p=function(a){return o.node=a,Promise.resolve(s).then(function(a){switch(s=a,!0){case e.isTransaction(s):return function(e,s){void 0===s&&(s={});try{return Promise.resolve(e).then(function(o){e=o;var a=new t.Transaction;a.setScript(Buffer.from(e.message.cadence,"utf8")),a.setGasLimit(e.message.computeLimit),a.setReferenceBlockId(e.message.refBlock?c(e.message.refBlock):null),a.setPayer(u(n.sansPrefix(e.accounts[e.payer].addr))),e.message.arguments.forEach(function(t){return a.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(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 a.addAuthorizers(u(n.sansPrefix(e)))});var g=new t.Transaction.ProposalKey;g.setAddress(u(n.sansPrefix(e.accounts[e.proposer].addr))),g.setKeyId(e.accounts[e.proposer].keyId),g.setSequenceNumber(e.accounts[e.proposer].sequenceNum),a.setProposalKey(g);for(var l=0,d=Object.values(e.accounts);l<d.length;l++){var f=d[l];try{if(null==f.signature)return;if(f.role.payer)return;var p=new t.Transaction.Signature;p.setAddress(u(n.sansPrefix(f.addr))),p.setKeyId(f.keyId),p.setSignature(c(f.signature)),a.addPayloadSignatures(p)}catch(t){throw console.error("Trouble applying payload signature",{acct:f,ix:e}),t}}for(var m=0,h=Object.values(e.accounts);m<h.length;m++){var v=h[m];try{if(null==v.signature)return;if(!v.role.payer)return;var I=new t.Transaction.Signature;I.setAddress(u(n.sansPrefix(v.addr))),I.setKeyId(v.keyId),I.setSignature(c(v.signature)),a.addEnvelopeSignatures(I)}catch(t){throw console.error("Trouble applying envelope signature",{acct:v,ix:e}),t}}var S=new t.SendTransactionRequest;return S.setTransaction(a),Promise.resolve(i(s.node,t.AccessAPI.SendTransaction,S)).then(function(t){var n,s=r.response();return s.tag=e.tag,s.transactionId=(n=t.getId_asU8(),Buffer.from(n).toString("hex")),console.log("SEND TX COMPLETE",{ret:s}),s})})}catch(e){return Promise.reject(e)}}(s,o);case e.isGetTransactionStatus(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.GetTransactionRequest;return o.setId(Buffer.from(e.transactionId,"hex")),Promise.resolve(i(n.node,t.AccessAPI.GetTransactionResult,o)).then(function(t){var n=t.getEventsList(),s=r.response();return s.tag=e.tag,s.transaction={status:t.getStatus(),statusCode:t.getStatusCode(),errorMessage:t.getErrorMessage(),events:n.map(function(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})},s})})}catch(e){return Promise.reject(e)}}(s,o);case e.isScript(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.ExecuteScriptAtLatestBlockRequest,a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return o.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(e.arguments[t].asArgument))}),o.setScript(a),Promise.resolve(i(n.node,t.AccessAPI.ExecuteScriptAtLatestBlock,o)).then(function(t){var n=r.response();return n.tag=e.tag,n.encodedData=JSON.parse(Buffer.from(t.getValue_asU8()).toString("utf8")),n})})}catch(e){return Promise.reject(e)}}(s,o);case e.isGetAccount(s):return function(e,s){void 0===s&&(s={});try{return Promise.resolve(e).then(function(o){e=o;var a,c=new t.GetAccountRequest;return c.setAddress((a=n.sansPrefix(e.accountAddr),Buffer.from(a.padStart(16,0),"hex"))),Promise.resolve(i(s.node,t.AccessAPI.GetAccount,c)).then(function(t){var s=r.response();s.tag=e.tag;var o=t.getAccount();return s.account={address:n.withPrefix(g(o.getAddress_asU8())),balance:o.getBalance(),code:o.getCode_asU8(),keys:o.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:g(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},s})})}catch(e){return Promise.reject(e)}}(s,o);case e.isGetEvents(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.GetEventsForHeightRangeRequest;return o.setType(e.events.eventType),o.setStartHeight(Number(e.events.start)),o.setEndHeight(Number(e.events.end)),Promise.resolve(i(n.node,t.AccessAPI.GetEventsForHeightRange,o)).then(function(t){var n=r.response();n.tag=e.tag;var s=t.getResultsList();return n.events=s.reduce(function(e,t){var r=t.getBlockId(),n=t.getBlockHeight();return t.getEventsList().forEach(function(t){var s;e.push({blockId:r,blockHeight:n,type:t.getType(),transactionId:(s=t.getTransactionId_asU8(),Buffer.from(s).toString("hex")),transactionIndex:t.getTransactionIndex(),eventIndex:t.getEventIndex(),payload:JSON.parse(Buffer.from(t.getPayload_asU8()).toString("utf8"))})}),e},[]),n})})}catch(e){return Promise.reject(e)}}(s,o);case e.isGetLatestBlock(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.GetLatestBlockRequest;return e.latestBlock&&e.latestBlock.isSealed&&(o.setIsSealed(e.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;")),e.block&&e.block.isSealed&&o.setIsSealed(e.block.isSealed),Promise.resolve(i(n.node,t.AccessAPI.GetLatestBlock,o)).then(function(t){var n=t.getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),a=n.getSignaturesList(),i=r.response();return i.tag=e.tag,i.block={id:l(n.getId_asU8()),parentId:l(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(function(e){return{collectionId:l(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:l(e.getBlockId_asU8()),executionReceiptId:l(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(s,o);case e.isGetBlockById(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.GetBlockByIDRequest;return o.setId(Buffer.from(e.block.id,"hex")),Promise.resolve(i(n.node,t.AccessAPI.GetBlockByID,o)).then(function(t){var n=t.getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),a=n.getSignaturesList(),i=r.response();return i.tag=e.tag,i.block={id:d(n.getId_asU8()),parentId:d(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(function(e){return{collectionId:d(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:d(e.getBlockId_asU8()),executionReceiptId:d(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(s,o);case e.isGetBlockByHeight(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.GetBlockByHeightRequest;return o.setHeight(e.block.height),Promise.resolve(i(n.node,t.AccessAPI.GetBlockByHeight,o)).then(function(t){var n=t.getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),a=n.getSignaturesList(),i=r.response();return i.tag=e.tag,i.block={id:f(n.getId_asU8()),parentId:f(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(function(e){return{collectionId:f(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:f(e.getBlockId_asU8()),executionReceiptId:f(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(s,o);case e.isPing(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.PingRequest;return Promise.resolve(i(n.node,t.AccessAPI.Ping,o)).then(function(t){var n=r.response();return n.tag=e.tag,n})})}catch(e){return Promise.reject(e)}}(s,o);default:return s}})},m=o.node;return Promise.resolve(m?p(m):Promise.resolve(a.config().get("accessNode.api")).then(p))}catch(e){return Promise.reject(e)}};
var e=require("@onflow/interaction"),t=require("@onflow/protobuf"),r=require("@onflow/response"),n=require("@onflow/util-address"),s=require("@improbable-eng/grpc-web"),o=require("@improbable-eng/grpc-web-node-http-transport"),a=require("@onflow/config"),i=function(e,t,r){try{return Promise.resolve(new Promise(function(n,o){s.grpc.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===s.grpc.Code.OK?n(e.message):o(new Error(t))}})}))}catch(e){return Promise.reject(e)}};s.grpc.setDefaultTransport(o.NodeHttpTransport());var c=function(e){return Buffer.from(e,"hex")},u=function(e){return Buffer.from(e.padStart(16,0),"hex")},g=function(e){return Buffer.from(e).toString("hex")},l=function(e){return Buffer.from(e).toString("hex")},d=function(e){return Buffer.from(e).toString("hex")},f=function(e){return Buffer.from(e).toString("hex")};exports.send=function(s,o){void 0===o&&(o={});try{var p=function(a){return o.node=a,Promise.resolve(s).then(function(a){switch(s=a,!0){case e.isTransaction(s):return function(e,s){void 0===s&&(s={});try{return Promise.resolve(e).then(function(o){e=o;var a=new t.Transaction;a.setScript(Buffer.from(e.message.cadence,"utf8")),a.setGasLimit(e.message.computeLimit),a.setReferenceBlockId(e.message.refBlock?c(e.message.refBlock):null),a.setPayer(u(n.sansPrefix(e.accounts[e.payer].addr))),e.message.arguments.forEach(function(t){return a.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(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 a.addAuthorizers(u(n.sansPrefix(e)))});var g=new t.Transaction.ProposalKey;g.setAddress(u(n.sansPrefix(e.accounts[e.proposer].addr))),g.setKeyId(e.accounts[e.proposer].keyId),g.setSequenceNumber(e.accounts[e.proposer].sequenceNum),a.setProposalKey(g);for(var l=0,d=Object.values(e.accounts);l<d.length;l++){var f=d[l];try{if(null==f.signature)return;if(f.role.payer)return;var p=new t.Transaction.Signature;p.setAddress(u(n.sansPrefix(f.addr))),p.setKeyId(f.keyId),p.setSignature(c(f.signature)),a.addPayloadSignatures(p)}catch(t){throw console.error("Trouble applying payload signature",{acct:f,ix:e}),t}}for(var m=0,h=Object.values(e.accounts);m<h.length;m++){var v=h[m];try{if(null==v.signature)return;if(!v.role.payer)return;var S=new t.Transaction.Signature;S.setAddress(u(n.sansPrefix(v.addr))),S.setKeyId(v.keyId),S.setSignature(c(v.signature)),a.addEnvelopeSignatures(S)}catch(t){throw console.error("Trouble applying envelope signature",{acct:v,ix:e}),t}}var I=new t.SendTransactionRequest;return I.setTransaction(a),console.log("UNARY_SEND",{req:I}),Promise.resolve(i(s.node,t.AccessAPI.SendTransaction,I)).then(function(t){console.log("UNARY_SENT",{res:t});var n,s=r.response();return s.tag=e.tag,s.transactionId=(n=t.getId_asU8(),Buffer.from(n).toString("hex")),console.log("SEND TX COMPLETE",{ret:s}),s})})}catch(e){return Promise.reject(e)}}(s,o);case e.isGetTransactionStatus(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.GetTransactionRequest;return o.setId(Buffer.from(e.transactionId,"hex")),Promise.resolve(i(n.node,t.AccessAPI.GetTransactionResult,o)).then(function(t){var n=t.getEventsList(),s=r.response();return s.tag=e.tag,s.transaction={status:t.getStatus(),statusCode:t.getStatusCode(),errorMessage:t.getErrorMessage(),events:n.map(function(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})},s})})}catch(e){return Promise.reject(e)}}(s,o);case e.isScript(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.ExecuteScriptAtLatestBlockRequest,a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return o.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(e.arguments[t].asArgument))}),o.setScript(a),Promise.resolve(i(n.node,t.AccessAPI.ExecuteScriptAtLatestBlock,o)).then(function(t){var n=r.response();return n.tag=e.tag,n.encodedData=JSON.parse(Buffer.from(t.getValue_asU8()).toString("utf8")),n})})}catch(e){return Promise.reject(e)}}(s,o);case e.isGetAccount(s):return function(e,s){void 0===s&&(s={});try{return Promise.resolve(e).then(function(o){e=o;var a,c=new t.GetAccountRequest;return c.setAddress((a=n.sansPrefix(e.accountAddr),Buffer.from(a.padStart(16,0),"hex"))),Promise.resolve(i(s.node,t.AccessAPI.GetAccount,c)).then(function(t){var s=r.response();s.tag=e.tag;var o=t.getAccount();return s.account={address:n.withPrefix(g(o.getAddress_asU8())),balance:o.getBalance(),code:o.getCode_asU8(),keys:o.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:g(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},s})})}catch(e){return Promise.reject(e)}}(s,o);case e.isGetEvents(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.GetEventsForHeightRangeRequest;return o.setType(e.events.eventType),o.setStartHeight(Number(e.events.start)),o.setEndHeight(Number(e.events.end)),Promise.resolve(i(n.node,t.AccessAPI.GetEventsForHeightRange,o)).then(function(t){var n=r.response();n.tag=e.tag;var s=t.getResultsList();return n.events=s.reduce(function(e,t){var r=t.getBlockId(),n=t.getBlockHeight();return t.getEventsList().forEach(function(t){var s;e.push({blockId:r,blockHeight:n,type:t.getType(),transactionId:(s=t.getTransactionId_asU8(),Buffer.from(s).toString("hex")),transactionIndex:t.getTransactionIndex(),eventIndex:t.getEventIndex(),payload:JSON.parse(Buffer.from(t.getPayload_asU8()).toString("utf8"))})}),e},[]),n})})}catch(e){return Promise.reject(e)}}(s,o);case e.isGetLatestBlock(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.GetLatestBlockRequest;return e.latestBlock&&e.latestBlock.isSealed&&(o.setIsSealed(e.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;")),e.block&&e.block.isSealed&&o.setIsSealed(e.block.isSealed),Promise.resolve(i(n.node,t.AccessAPI.GetLatestBlock,o)).then(function(t){var n=t.getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),a=n.getSignaturesList(),i=r.response();return i.tag=e.tag,i.block={id:l(n.getId_asU8()),parentId:l(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(function(e){return{collectionId:l(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:l(e.getBlockId_asU8()),executionReceiptId:l(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(s,o);case e.isGetBlockById(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.GetBlockByIDRequest;return o.setId(Buffer.from(e.block.id,"hex")),Promise.resolve(i(n.node,t.AccessAPI.GetBlockByID,o)).then(function(t){var n=t.getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),a=n.getSignaturesList(),i=r.response();return i.tag=e.tag,i.block={id:d(n.getId_asU8()),parentId:d(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(function(e){return{collectionId:d(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:d(e.getBlockId_asU8()),executionReceiptId:d(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(s,o);case e.isGetBlockByHeight(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.GetBlockByHeightRequest;return o.setHeight(e.block.height),Promise.resolve(i(n.node,t.AccessAPI.GetBlockByHeight,o)).then(function(t){var n=t.getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),a=n.getSignaturesList(),i=r.response();return i.tag=e.tag,i.block={id:f(n.getId_asU8()),parentId:f(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(function(e){return{collectionId:f(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:f(e.getBlockId_asU8()),executionReceiptId:f(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(s,o);case e.isPing(s):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.PingRequest;return Promise.resolve(i(n.node,t.AccessAPI.Ping,o)).then(function(t){var n=r.response();return n.tag=e.tag,n})})}catch(e){return Promise.reject(e)}}(s,o);default:return s}})},m=o.node;return Promise.resolve(m?p(m):Promise.resolve(a.config().get("accessNode.api")).then(p))}catch(e){return Promise.reject(e)}};
//# sourceMappingURL=send.js.map

@@ -1,2 +0,2 @@

import{isPing as e,isGetBlockByHeight as t,isGetBlockById as a,isGetLatestBlock as n,isGetEvents as s,isGetAccount as o,isScript as r,isGetTransactionStatus as i,isTransaction as c}from"@onflow/interaction";import{Transaction as g,SendTransactionRequest as u,AccessAPI as l,GetTransactionRequest as d,ExecuteScriptAtLatestBlockRequest as f,GetAccountRequest as p,GetEventsForHeightRangeRequest as m,GetLatestBlockRequest as S,GetBlockByIDRequest as I,GetBlockByHeightRequest as h,PingRequest as w}from"@onflow/protobuf";import{response as y}from"@onflow/response";import{sansPrefix as k,withPrefix as B}from"@onflow/util-address";import{grpc as b}from"@improbable-eng/grpc-web";import{NodeHttpTransport as x}from"@improbable-eng/grpc-web-node-http-transport";import{config as v}from"@onflow/config";async function L(e,t,a){return new Promise((n,s)=>{b.unary(t,{request:a,host:e,onEnd:({status:e,statusMessage:t,message:a})=>{e===b.Code.OK?n(a):s(new Error(t))}})})}b.setDefaultTransport(x());const A=e=>Buffer.from(e,"hex"),E=e=>Buffer.from(e.padStart(16,0),"hex"),U=e=>Buffer.from(e).toString("hex"),_=e=>Buffer.from(e).toString("hex"),R=e=>Buffer.from(e).toString("hex"),T=e=>Buffer.from(e).toString("hex"),N=async(b,x={})=>{switch(x.node=x.node||await v().get("accessNode.api"),b=await b,!0){case c(b):return async function(e,t={}){e=await e;const a=new g;a.setScript(Buffer.from(e.message.cadence,"utf8")),a.setGasLimit(e.message.computeLimit),a.setReferenceBlockId(e.message.refBlock?A(e.message.refBlock):null),a.setPayer(E(k(e.accounts[e.payer].addr))),e.message.arguments.forEach(t=>a.addArguments((e=>Buffer.from(JSON.stringify(e),"utf8"))(e.arguments[t].asArgument))),e.authorizations.map(t=>e.accounts[t].addr).reduce((e,t)=>e.find(e=>e===t)?e:[...e,t],[]).forEach(e=>a.addAuthorizers(E(k(e))));const n=new g.ProposalKey;n.setAddress(E(k(e.accounts[e.proposer].addr))),n.setKeyId(e.accounts[e.proposer].keyId),n.setSequenceNumber(e.accounts[e.proposer].sequenceNum),a.setProposalKey(n);for(let t of Object.values(e.accounts))try{if(null==t.signature)continue;if(t.role.payer)continue;const e=new g.Signature;e.setAddress(E(k(t.addr))),e.setKeyId(t.keyId),e.setSignature(A(t.signature)),a.addPayloadSignatures(e)}catch(a){throw console.error("Trouble applying payload signature",{acct:t,ix:e}),a}for(let t of Object.values(e.accounts))try{if(null==t.signature)continue;if(!t.role.payer)continue;const e=new g.Signature;e.setAddress(E(k(t.addr))),e.setKeyId(t.keyId),e.setSignature(A(t.signature)),a.addEnvelopeSignatures(e)}catch(a){throw console.error("Trouble applying envelope signature",{acct:t,ix:e}),a}const s=new u;s.setTransaction(a);const o=await L(t.node,l.SendTransaction,s);let r=y();var i;return r.tag=e.tag,r.transactionId=(i=o.getId_asU8(),Buffer.from(i).toString("hex")),console.log("SEND TX COMPLETE",{ret:r}),r}(b,x);case i(b):return async function(e,t={}){e=await e;const a=new d;a.setId(Buffer.from(e.transactionId,"hex"));const n=await L(t.node,l.GetTransactionResult,a);let s=n.getEventsList(),o=y();return o.tag=e.tag,o.transaction={status:n.getStatus(),statusCode:n.getStatusCode(),errorMessage:n.getErrorMessage(),events:s.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})},o}(b,x);case r(b):return async function(e,t={}){e=await e;const a=new f,n=Buffer.from(e.message.cadence,"utf8");e.message.arguments.forEach(t=>a.addArguments((e=>Buffer.from(JSON.stringify(e),"utf8"))(e.arguments[t].asArgument))),a.setScript(n);const s=await L(t.node,l.ExecuteScriptAtLatestBlock,a);let o=y();return o.tag=e.tag,o.encodedData=JSON.parse(Buffer.from(s.getValue_asU8()).toString("utf8")),o}(b,x);case o(b):return async function(e,t={}){e=await e;const a=new p;var n;a.setAddress((n=k(e.accountAddr),Buffer.from(n.padStart(16,0),"hex")));const s=await L(t.node,l.GetAccount,a);let o=y();o.tag=e.tag;const r=s.getAccount();return o.account={address:B(U(r.getAddress_asU8())),balance:r.getBalance(),code:r.getCode_asU8(),keys:r.getKeysList().map(e=>({index:e.getIndex(),publicKey:U(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}))},o}(b,x);case s(b):return async function(e,t={}){e=await e;const a=new m;a.setType(e.events.eventType),a.setStartHeight(Number(e.events.start)),a.setEndHeight(Number(e.events.end));const n=await L(t.node,l.GetEventsForHeightRange,a);let s=y();s.tag=e.tag;const o=n.getResultsList();return s.events=o.reduce((e,t)=>{const a=t.getBlockId(),n=t.getBlockHeight();return t.getEventsList().forEach(t=>{var s;e.push({blockId:a,blockHeight:n,type:t.getType(),transactionId:(s=t.getTransactionId_asU8(),Buffer.from(s).toString("hex")),transactionIndex:t.getTransactionIndex(),eventIndex:t.getEventIndex(),payload:JSON.parse(Buffer.from(t.getPayload_asU8()).toString("utf8"))})}),e},[]),s}(b,x);case n(b):return async function(e,t={}){e=await e;const a=new S;e.latestBlock&&e.latestBlock.isSealed&&(a.setIsSealed(e.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;")),e.block&&e.block.isSealed&&a.setIsSealed(e.block.isSealed);const n=(await L(t.node,l.GetLatestBlock,a)).getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),r=n.getSignaturesList(),i=y();return i.tag=e.tag,i.block={id:_(n.getId_asU8()),parentId:_(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(e=>({collectionId:_(e.getCollectionId_asU8()),signatures:e.getSignaturesList()})),blockSeals:o.map(e=>({blockId:_(e.getBlockId_asU8()),executionReceiptId:_(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:r},i}(b,x);case a(b):return async function(e,t={}){e=await e;const a=new I;a.setId(Buffer.from(e.block.id,"hex"));const n=(await L(t.node,l.GetBlockByID,a)).getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),r=n.getSignaturesList(),i=y();return i.tag=e.tag,i.block={id:R(n.getId_asU8()),parentId:R(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(e=>({collectionId:R(e.getCollectionId_asU8()),signatures:e.getSignaturesList()})),blockSeals:o.map(e=>({blockId:R(e.getBlockId_asU8()),executionReceiptId:R(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:r},i}(b,x);case t(b):return async function(e,t={}){e=await e;const a=new h;a.setHeight(e.block.height);const n=(await L(t.node,l.GetBlockByHeight,a)).getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),r=n.getSignaturesList(),i=y();return i.tag=e.tag,i.block={id:T(n.getId_asU8()),parentId:T(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(e=>({collectionId:T(e.getCollectionId_asU8()),signatures:e.getSignaturesList()})),blockSeals:o.map(e=>({blockId:T(e.getBlockId_asU8()),executionReceiptId:T(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:r},i}(b,x);case e(b):return async function(e,t={}){e=await e;const a=new w;await L(t.node,l.Ping,a);let n=y();return n.tag=e.tag,n}(b,x);default:return b}};export{N as send};
import{isPing as e,isGetBlockByHeight as t,isGetBlockById as a,isGetLatestBlock as n,isGetEvents as s,isGetAccount as o,isScript as r,isGetTransactionStatus as i,isTransaction as c}from"@onflow/interaction";import{Transaction as g,SendTransactionRequest as u,AccessAPI as l,GetTransactionRequest as d,ExecuteScriptAtLatestBlockRequest as f,GetAccountRequest as p,GetEventsForHeightRangeRequest as m,GetLatestBlockRequest as S,GetBlockByIDRequest as I,GetBlockByHeightRequest as h,PingRequest as w}from"@onflow/protobuf";import{response as y}from"@onflow/response";import{sansPrefix as k,withPrefix as B}from"@onflow/util-address";import{grpc as b}from"@improbable-eng/grpc-web";import{NodeHttpTransport as x}from"@improbable-eng/grpc-web-node-http-transport";import{config as v}from"@onflow/config";async function A(e,t,a){return new Promise((n,s)=>{b.unary(t,{request:a,host:e,onEnd:({status:e,statusMessage:t,message:a})=>{e===b.Code.OK?n(a):s(new Error(t))}})})}b.setDefaultTransport(x());const L=e=>Buffer.from(e,"hex"),E=e=>Buffer.from(e.padStart(16,0),"hex"),U=e=>Buffer.from(e).toString("hex"),_=e=>Buffer.from(e).toString("hex"),R=e=>Buffer.from(e).toString("hex"),N=e=>Buffer.from(e).toString("hex"),T=async(b,x={})=>{switch(x.node=x.node||await v().get("accessNode.api"),b=await b,!0){case c(b):return async function(e,t={}){e=await e;const a=new g;a.setScript(Buffer.from(e.message.cadence,"utf8")),a.setGasLimit(e.message.computeLimit),a.setReferenceBlockId(e.message.refBlock?L(e.message.refBlock):null),a.setPayer(E(k(e.accounts[e.payer].addr))),e.message.arguments.forEach(t=>a.addArguments((e=>Buffer.from(JSON.stringify(e),"utf8"))(e.arguments[t].asArgument))),e.authorizations.map(t=>e.accounts[t].addr).reduce((e,t)=>e.find(e=>e===t)?e:[...e,t],[]).forEach(e=>a.addAuthorizers(E(k(e))));const n=new g.ProposalKey;n.setAddress(E(k(e.accounts[e.proposer].addr))),n.setKeyId(e.accounts[e.proposer].keyId),n.setSequenceNumber(e.accounts[e.proposer].sequenceNum),a.setProposalKey(n);for(let t of Object.values(e.accounts))try{if(null==t.signature)continue;if(t.role.payer)continue;const e=new g.Signature;e.setAddress(E(k(t.addr))),e.setKeyId(t.keyId),e.setSignature(L(t.signature)),a.addPayloadSignatures(e)}catch(a){throw console.error("Trouble applying payload signature",{acct:t,ix:e}),a}for(let t of Object.values(e.accounts))try{if(null==t.signature)continue;if(!t.role.payer)continue;const e=new g.Signature;e.setAddress(E(k(t.addr))),e.setKeyId(t.keyId),e.setSignature(L(t.signature)),a.addEnvelopeSignatures(e)}catch(a){throw console.error("Trouble applying envelope signature",{acct:t,ix:e}),a}const s=new u;s.setTransaction(a),console.log("UNARY_SEND",{req:s});const o=await A(t.node,l.SendTransaction,s);console.log("UNARY_SENT",{res:o});let r=y();var i;return r.tag=e.tag,r.transactionId=(i=o.getId_asU8(),Buffer.from(i).toString("hex")),console.log("SEND TX COMPLETE",{ret:r}),r}(b,x);case i(b):return async function(e,t={}){e=await e;const a=new d;a.setId(Buffer.from(e.transactionId,"hex"));const n=await A(t.node,l.GetTransactionResult,a);let s=n.getEventsList(),o=y();return o.tag=e.tag,o.transaction={status:n.getStatus(),statusCode:n.getStatusCode(),errorMessage:n.getErrorMessage(),events:s.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})},o}(b,x);case r(b):return async function(e,t={}){e=await e;const a=new f,n=Buffer.from(e.message.cadence,"utf8");e.message.arguments.forEach(t=>a.addArguments((e=>Buffer.from(JSON.stringify(e),"utf8"))(e.arguments[t].asArgument))),a.setScript(n);const s=await A(t.node,l.ExecuteScriptAtLatestBlock,a);let o=y();return o.tag=e.tag,o.encodedData=JSON.parse(Buffer.from(s.getValue_asU8()).toString("utf8")),o}(b,x);case o(b):return async function(e,t={}){e=await e;const a=new p;var n;a.setAddress((n=k(e.accountAddr),Buffer.from(n.padStart(16,0),"hex")));const s=await A(t.node,l.GetAccount,a);let o=y();o.tag=e.tag;const r=s.getAccount();return o.account={address:B(U(r.getAddress_asU8())),balance:r.getBalance(),code:r.getCode_asU8(),keys:r.getKeysList().map(e=>({index:e.getIndex(),publicKey:U(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}))},o}(b,x);case s(b):return async function(e,t={}){e=await e;const a=new m;a.setType(e.events.eventType),a.setStartHeight(Number(e.events.start)),a.setEndHeight(Number(e.events.end));const n=await A(t.node,l.GetEventsForHeightRange,a);let s=y();s.tag=e.tag;const o=n.getResultsList();return s.events=o.reduce((e,t)=>{const a=t.getBlockId(),n=t.getBlockHeight();return t.getEventsList().forEach(t=>{var s;e.push({blockId:a,blockHeight:n,type:t.getType(),transactionId:(s=t.getTransactionId_asU8(),Buffer.from(s).toString("hex")),transactionIndex:t.getTransactionIndex(),eventIndex:t.getEventIndex(),payload:JSON.parse(Buffer.from(t.getPayload_asU8()).toString("utf8"))})}),e},[]),s}(b,x);case n(b):return async function(e,t={}){e=await e;const a=new S;e.latestBlock&&e.latestBlock.isSealed&&(a.setIsSealed(e.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;")),e.block&&e.block.isSealed&&a.setIsSealed(e.block.isSealed);const n=(await A(t.node,l.GetLatestBlock,a)).getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),r=n.getSignaturesList(),i=y();return i.tag=e.tag,i.block={id:_(n.getId_asU8()),parentId:_(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(e=>({collectionId:_(e.getCollectionId_asU8()),signatures:e.getSignaturesList()})),blockSeals:o.map(e=>({blockId:_(e.getBlockId_asU8()),executionReceiptId:_(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:r},i}(b,x);case a(b):return async function(e,t={}){e=await e;const a=new I;a.setId(Buffer.from(e.block.id,"hex"));const n=(await A(t.node,l.GetBlockByID,a)).getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),r=n.getSignaturesList(),i=y();return i.tag=e.tag,i.block={id:R(n.getId_asU8()),parentId:R(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(e=>({collectionId:R(e.getCollectionId_asU8()),signatures:e.getSignaturesList()})),blockSeals:o.map(e=>({blockId:R(e.getBlockId_asU8()),executionReceiptId:R(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:r},i}(b,x);case t(b):return async function(e,t={}){e=await e;const a=new h;a.setHeight(e.block.height);const n=(await A(t.node,l.GetBlockByHeight,a)).getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),r=n.getSignaturesList(),i=y();return i.tag=e.tag,i.block={id:N(n.getId_asU8()),parentId:N(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(e=>({collectionId:N(e.getCollectionId_asU8()),signatures:e.getSignaturesList()})),blockSeals:o.map(e=>({blockId:N(e.getBlockId_asU8()),executionReceiptId:N(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:r},i}(b,x);case e(b):return async function(e,t={}){e=await e;const a=new w;await A(t.node,l.Ping,a);let n=y();return n.tag=e.tag,n}(b,x);default:return b}};export{T as send};
//# sourceMappingURL=send.modern.js.map

@@ -1,2 +0,2 @@

import{isPing as e,isGetBlockByHeight as t,isGetBlockById as r,isGetLatestBlock as n,isGetEvents as o,isGetAccount as s,isScript as a,isGetTransactionStatus as i,isTransaction as u}from"@onflow/interaction";import{Transaction as c,SendTransactionRequest as g,AccessAPI as l,GetTransactionRequest as f,ExecuteScriptAtLatestBlockRequest as d,GetAccountRequest as m,GetEventsForHeightRangeRequest as p,GetLatestBlockRequest as v,GetBlockByIDRequest as h,GetBlockByHeightRequest as S,PingRequest as I}from"@onflow/protobuf";import{response as y}from"@onflow/response";import{sansPrefix as P,withPrefix as k}from"@onflow/util-address";import{grpc as B}from"@improbable-eng/grpc-web";import{NodeHttpTransport as b}from"@improbable-eng/grpc-web-node-http-transport";import{config as x}from"@onflow/config";var w=function(e,t,r){try{return Promise.resolve(new Promise(function(n,o){B.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===B.Code.OK?n(e.message):o(new Error(t))}})}))}catch(e){return Promise.reject(e)}};B.setDefaultTransport(b());var L=function(e){return Buffer.from(e,"hex")},A=function(e){return Buffer.from(e.padStart(16,0),"hex")},E=function(e){return Buffer.from(e).toString("hex")},U=function(e){return Buffer.from(e).toString("hex")},_=function(e){return Buffer.from(e).toString("hex")},R=function(e){return Buffer.from(e).toString("hex")},T=function(B,b){void 0===b&&(b={});try{var T=function(x){return b.node=x,Promise.resolve(B).then(function(x){switch(B=x,!0){case u(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new c;n.setScript(Buffer.from(e.message.cadence,"utf8")),n.setGasLimit(e.message.computeLimit),n.setReferenceBlockId(e.message.refBlock?L(e.message.refBlock):null),n.setPayer(A(P(e.accounts[e.payer].addr))),e.message.arguments.forEach(function(t){return n.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(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 n.addAuthorizers(A(P(e)))});var o=new c.ProposalKey;o.setAddress(A(P(e.accounts[e.proposer].addr))),o.setKeyId(e.accounts[e.proposer].keyId),o.setSequenceNumber(e.accounts[e.proposer].sequenceNum),n.setProposalKey(o);for(var s=0,a=Object.values(e.accounts);s<a.length;s++){var i=a[s];try{if(null==i.signature)return;if(i.role.payer)return;var u=new c.Signature;u.setAddress(A(P(i.addr))),u.setKeyId(i.keyId),u.setSignature(L(i.signature)),n.addPayloadSignatures(u)}catch(t){throw console.error("Trouble applying payload signature",{acct:i,ix:e}),t}}for(var f=0,d=Object.values(e.accounts);f<d.length;f++){var m=d[f];try{if(null==m.signature)return;if(!m.role.payer)return;var p=new c.Signature;p.setAddress(A(P(m.addr))),p.setKeyId(m.keyId),p.setSignature(L(m.signature)),n.addEnvelopeSignatures(p)}catch(t){throw console.error("Trouble applying envelope signature",{acct:m,ix:e}),t}}var v=new g;return v.setTransaction(n),Promise.resolve(w(t.node,l.SendTransaction,v)).then(function(t){var r,n=y();return n.tag=e.tag,n.transactionId=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),console.log("SEND TX COMPLETE",{ret:n}),n})})}catch(e){return Promise.reject(e)}}(B,b);case i(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new f;return n.setId(Buffer.from(e.transactionId,"hex")),Promise.resolve(w(t.node,l.GetTransactionResult,n)).then(function(t){var r=t.getEventsList(),n=y();return n.tag=e.tag,n.transaction={status:t.getStatus(),statusCode:t.getStatusCode(),errorMessage:t.getErrorMessage(),events:r.map(function(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})},n})})}catch(e){return Promise.reject(e)}}(B,b);case a(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new d,o=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return n.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(e.arguments[t].asArgument))}),n.setScript(o),Promise.resolve(w(t.node,l.ExecuteScriptAtLatestBlock,n)).then(function(t){var r=y();return r.tag=e.tag,r.encodedData=JSON.parse(Buffer.from(t.getValue_asU8()).toString("utf8")),r})})}catch(e){return Promise.reject(e)}}(B,b);case s(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n,o=new m;return o.setAddress((n=P(e.accountAddr),Buffer.from(n.padStart(16,0),"hex"))),Promise.resolve(w(t.node,l.GetAccount,o)).then(function(t){var r=y();r.tag=e.tag;var n=t.getAccount();return r.account={address:k(E(n.getAddress_asU8())),balance:n.getBalance(),code:n.getCode_asU8(),keys:n.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:E(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},r})})}catch(e){return Promise.reject(e)}}(B,b);case o(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new p;return n.setType(e.events.eventType),n.setStartHeight(Number(e.events.start)),n.setEndHeight(Number(e.events.end)),Promise.resolve(w(t.node,l.GetEventsForHeightRange,n)).then(function(t){var r=y();r.tag=e.tag;var n=t.getResultsList();return r.events=n.reduce(function(e,t){var r=t.getBlockId(),n=t.getBlockHeight();return t.getEventsList().forEach(function(t){var o;e.push({blockId:r,blockHeight:n,type:t.getType(),transactionId:(o=t.getTransactionId_asU8(),Buffer.from(o).toString("hex")),transactionIndex:t.getTransactionIndex(),eventIndex:t.getEventIndex(),payload:JSON.parse(Buffer.from(t.getPayload_asU8()).toString("utf8"))})}),e},[]),r})})}catch(e){return Promise.reject(e)}}(B,b);case n(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new v;return e.latestBlock&&e.latestBlock.isSealed&&(n.setIsSealed(e.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;")),e.block&&e.block.isSealed&&n.setIsSealed(e.block.isSealed),Promise.resolve(w(t.node,l.GetLatestBlock,n)).then(function(t){var r=t.getBlock(),n=r.getCollectionGuaranteesList(),o=r.getBlockSealsList(),s=r.getSignaturesList(),a=y();return a.tag=e.tag,a.block={id:U(r.getId_asU8()),parentId:U(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:U(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:U(e.getBlockId_asU8()),executionReceiptId:U(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:s},a})})}catch(e){return Promise.reject(e)}}(B,b);case r(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new h;return n.setId(Buffer.from(e.block.id,"hex")),Promise.resolve(w(t.node,l.GetBlockByID,n)).then(function(t){var r=t.getBlock(),n=r.getCollectionGuaranteesList(),o=r.getBlockSealsList(),s=r.getSignaturesList(),a=y();return a.tag=e.tag,a.block={id:_(r.getId_asU8()),parentId:_(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:_(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:_(e.getBlockId_asU8()),executionReceiptId:_(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:s},a})})}catch(e){return Promise.reject(e)}}(B,b);case t(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new S;return n.setHeight(e.block.height),Promise.resolve(w(t.node,l.GetBlockByHeight,n)).then(function(t){var r=t.getBlock(),n=r.getCollectionGuaranteesList(),o=r.getBlockSealsList(),s=r.getSignaturesList(),a=y();return a.tag=e.tag,a.block={id:R(r.getId_asU8()),parentId:R(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:R(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:R(e.getBlockId_asU8()),executionReceiptId:R(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:s},a})})}catch(e){return Promise.reject(e)}}(B,b);case e(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new I;return Promise.resolve(w(t.node,l.Ping,n)).then(function(t){var r=y();return r.tag=e.tag,r})})}catch(e){return Promise.reject(e)}}(B,b);default:return B}})},N=b.node;return Promise.resolve(N?T(N):Promise.resolve(x().get("accessNode.api")).then(T))}catch(e){return Promise.reject(e)}};export{T as send};
import{isPing as e,isGetBlockByHeight as t,isGetBlockById as r,isGetLatestBlock as n,isGetEvents as o,isGetAccount as s,isScript as a,isGetTransactionStatus as i,isTransaction as u}from"@onflow/interaction";import{Transaction as c,SendTransactionRequest as g,AccessAPI as l,GetTransactionRequest as f,ExecuteScriptAtLatestBlockRequest as d,GetAccountRequest as m,GetEventsForHeightRangeRequest as p,GetLatestBlockRequest as v,GetBlockByIDRequest as h,GetBlockByHeightRequest as S,PingRequest as I}from"@onflow/protobuf";import{response as y}from"@onflow/response";import{sansPrefix as P,withPrefix as k}from"@onflow/util-address";import{grpc as B}from"@improbable-eng/grpc-web";import{NodeHttpTransport as b}from"@improbable-eng/grpc-web-node-http-transport";import{config as x}from"@onflow/config";var w=function(e,t,r){try{return Promise.resolve(new Promise(function(n,o){B.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===B.Code.OK?n(e.message):o(new Error(t))}})}))}catch(e){return Promise.reject(e)}};B.setDefaultTransport(b());var A=function(e){return Buffer.from(e,"hex")},L=function(e){return Buffer.from(e.padStart(16,0),"hex")},E=function(e){return Buffer.from(e).toString("hex")},U=function(e){return Buffer.from(e).toString("hex")},_=function(e){return Buffer.from(e).toString("hex")},R=function(e){return Buffer.from(e).toString("hex")},N=function(B,b){void 0===b&&(b={});try{var N=function(x){return b.node=x,Promise.resolve(B).then(function(x){switch(B=x,!0){case u(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new c;n.setScript(Buffer.from(e.message.cadence,"utf8")),n.setGasLimit(e.message.computeLimit),n.setReferenceBlockId(e.message.refBlock?A(e.message.refBlock):null),n.setPayer(L(P(e.accounts[e.payer].addr))),e.message.arguments.forEach(function(t){return n.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(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 n.addAuthorizers(L(P(e)))});var o=new c.ProposalKey;o.setAddress(L(P(e.accounts[e.proposer].addr))),o.setKeyId(e.accounts[e.proposer].keyId),o.setSequenceNumber(e.accounts[e.proposer].sequenceNum),n.setProposalKey(o);for(var s=0,a=Object.values(e.accounts);s<a.length;s++){var i=a[s];try{if(null==i.signature)return;if(i.role.payer)return;var u=new c.Signature;u.setAddress(L(P(i.addr))),u.setKeyId(i.keyId),u.setSignature(A(i.signature)),n.addPayloadSignatures(u)}catch(t){throw console.error("Trouble applying payload signature",{acct:i,ix:e}),t}}for(var f=0,d=Object.values(e.accounts);f<d.length;f++){var m=d[f];try{if(null==m.signature)return;if(!m.role.payer)return;var p=new c.Signature;p.setAddress(L(P(m.addr))),p.setKeyId(m.keyId),p.setSignature(A(m.signature)),n.addEnvelopeSignatures(p)}catch(t){throw console.error("Trouble applying envelope signature",{acct:m,ix:e}),t}}var v=new g;return v.setTransaction(n),console.log("UNARY_SEND",{req:v}),Promise.resolve(w(t.node,l.SendTransaction,v)).then(function(t){console.log("UNARY_SENT",{res:t});var r,n=y();return n.tag=e.tag,n.transactionId=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),console.log("SEND TX COMPLETE",{ret:n}),n})})}catch(e){return Promise.reject(e)}}(B,b);case i(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new f;return n.setId(Buffer.from(e.transactionId,"hex")),Promise.resolve(w(t.node,l.GetTransactionResult,n)).then(function(t){var r=t.getEventsList(),n=y();return n.tag=e.tag,n.transaction={status:t.getStatus(),statusCode:t.getStatusCode(),errorMessage:t.getErrorMessage(),events:r.map(function(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})},n})})}catch(e){return Promise.reject(e)}}(B,b);case a(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new d,o=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return n.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(e.arguments[t].asArgument))}),n.setScript(o),Promise.resolve(w(t.node,l.ExecuteScriptAtLatestBlock,n)).then(function(t){var r=y();return r.tag=e.tag,r.encodedData=JSON.parse(Buffer.from(t.getValue_asU8()).toString("utf8")),r})})}catch(e){return Promise.reject(e)}}(B,b);case s(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n,o=new m;return o.setAddress((n=P(e.accountAddr),Buffer.from(n.padStart(16,0),"hex"))),Promise.resolve(w(t.node,l.GetAccount,o)).then(function(t){var r=y();r.tag=e.tag;var n=t.getAccount();return r.account={address:k(E(n.getAddress_asU8())),balance:n.getBalance(),code:n.getCode_asU8(),keys:n.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:E(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},r})})}catch(e){return Promise.reject(e)}}(B,b);case o(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new p;return n.setType(e.events.eventType),n.setStartHeight(Number(e.events.start)),n.setEndHeight(Number(e.events.end)),Promise.resolve(w(t.node,l.GetEventsForHeightRange,n)).then(function(t){var r=y();r.tag=e.tag;var n=t.getResultsList();return r.events=n.reduce(function(e,t){var r=t.getBlockId(),n=t.getBlockHeight();return t.getEventsList().forEach(function(t){var o;e.push({blockId:r,blockHeight:n,type:t.getType(),transactionId:(o=t.getTransactionId_asU8(),Buffer.from(o).toString("hex")),transactionIndex:t.getTransactionIndex(),eventIndex:t.getEventIndex(),payload:JSON.parse(Buffer.from(t.getPayload_asU8()).toString("utf8"))})}),e},[]),r})})}catch(e){return Promise.reject(e)}}(B,b);case n(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new v;return e.latestBlock&&e.latestBlock.isSealed&&(n.setIsSealed(e.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;")),e.block&&e.block.isSealed&&n.setIsSealed(e.block.isSealed),Promise.resolve(w(t.node,l.GetLatestBlock,n)).then(function(t){var r=t.getBlock(),n=r.getCollectionGuaranteesList(),o=r.getBlockSealsList(),s=r.getSignaturesList(),a=y();return a.tag=e.tag,a.block={id:U(r.getId_asU8()),parentId:U(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:U(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:U(e.getBlockId_asU8()),executionReceiptId:U(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:s},a})})}catch(e){return Promise.reject(e)}}(B,b);case r(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new h;return n.setId(Buffer.from(e.block.id,"hex")),Promise.resolve(w(t.node,l.GetBlockByID,n)).then(function(t){var r=t.getBlock(),n=r.getCollectionGuaranteesList(),o=r.getBlockSealsList(),s=r.getSignaturesList(),a=y();return a.tag=e.tag,a.block={id:_(r.getId_asU8()),parentId:_(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:_(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:_(e.getBlockId_asU8()),executionReceiptId:_(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:s},a})})}catch(e){return Promise.reject(e)}}(B,b);case t(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new S;return n.setHeight(e.block.height),Promise.resolve(w(t.node,l.GetBlockByHeight,n)).then(function(t){var r=t.getBlock(),n=r.getCollectionGuaranteesList(),o=r.getBlockSealsList(),s=r.getSignaturesList(),a=y();return a.tag=e.tag,a.block={id:R(r.getId_asU8()),parentId:R(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:R(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:R(e.getBlockId_asU8()),executionReceiptId:R(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:s},a})})}catch(e){return Promise.reject(e)}}(B,b);case e(B):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new I;return Promise.resolve(w(t.node,l.Ping,n)).then(function(t){var r=y();return r.tag=e.tag,r})})}catch(e){return Promise.reject(e)}}(B,b);default:return B}})},T=b.node;return Promise.resolve(T?N(T):Promise.resolve(x().get("accessNode.api")).then(N))}catch(e){return Promise.reject(e)}};export{N as send};
//# sourceMappingURL=send.module.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@onflow/interaction"),require("@onflow/protobuf"),require("@onflow/response"),require("@onflow/util-address"),require("@improbable-eng/grpc-web"),require("@improbable-eng/grpc-web-node-http-transport"),require("@onflow/config")):"function"==typeof define&&define.amd?define(["exports","@onflow/interaction","@onflow/protobuf","@onflow/response","@onflow/util-address","@improbable-eng/grpc-web","@improbable-eng/grpc-web-node-http-transport","@onflow/config"],t):t((e=e||self).send={},e.interaction,e.protobuf,e.response,e.utilAddress,e.grpcWeb,e.grpcWebNodeHttpTransport,e.config)}(this,function(e,t,r,n,o,s,a,i){var c=function(e,t,r){try{return Promise.resolve(new Promise(function(n,o){s.grpc.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===s.grpc.Code.OK?n(e.message):o(new Error(t))}})}))}catch(e){return Promise.reject(e)}};s.grpc.setDefaultTransport(a.NodeHttpTransport());var u=function(e){return Buffer.from(e,"hex")},g=function(e){return Buffer.from(e.padStart(16,0),"hex")},l=function(e){return Buffer.from(e).toString("hex")},f=function(e){return Buffer.from(e).toString("hex")},d=function(e){return Buffer.from(e).toString("hex")},p=function(e){return Buffer.from(e).toString("hex")};e.send=function(e,s){void 0===s&&(s={});try{var a=function(a){return s.node=a,Promise.resolve(e).then(function(a){switch(e=a,!0){case t.isTransaction(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(s){e=s;var a=new r.Transaction;a.setScript(Buffer.from(e.message.cadence,"utf8")),a.setGasLimit(e.message.computeLimit),a.setReferenceBlockId(e.message.refBlock?u(e.message.refBlock):null),a.setPayer(g(o.sansPrefix(e.accounts[e.payer].addr))),e.message.arguments.forEach(function(t){return a.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(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 a.addAuthorizers(g(o.sansPrefix(e)))});var i=new r.Transaction.ProposalKey;i.setAddress(g(o.sansPrefix(e.accounts[e.proposer].addr))),i.setKeyId(e.accounts[e.proposer].keyId),i.setSequenceNumber(e.accounts[e.proposer].sequenceNum),a.setProposalKey(i);for(var l=0,f=Object.values(e.accounts);l<f.length;l++){var d=f[l];try{if(null==d.signature)return;if(d.role.payer)return;var p=new r.Transaction.Signature;p.setAddress(g(o.sansPrefix(d.addr))),p.setKeyId(d.keyId),p.setSignature(u(d.signature)),a.addPayloadSignatures(p)}catch(t){throw console.error("Trouble applying payload signature",{acct:d,ix:e}),t}}for(var m=0,h=Object.values(e.accounts);m<h.length;m++){var v=h[m];try{if(null==v.signature)return;if(!v.role.payer)return;var I=new r.Transaction.Signature;I.setAddress(g(o.sansPrefix(v.addr))),I.setKeyId(v.keyId),I.setSignature(u(v.signature)),a.addEnvelopeSignatures(I)}catch(t){throw console.error("Trouble applying envelope signature",{acct:v,ix:e}),t}}var S=new r.SendTransactionRequest;return S.setTransaction(a),Promise.resolve(c(t.node,r.AccessAPI.SendTransaction,S)).then(function(t){var r,o=n.response();return o.tag=e.tag,o.transactionId=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),console.log("SEND TX COMPLETE",{ret:o}),o})})}catch(e){return Promise.reject(e)}}(e,s);case t.isGetTransactionStatus(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.GetTransactionRequest;return s.setId(Buffer.from(e.transactionId,"hex")),Promise.resolve(c(t.node,r.AccessAPI.GetTransactionResult,s)).then(function(t){var r=t.getEventsList(),o=n.response();return o.tag=e.tag,o.transaction={status:t.getStatus(),statusCode:t.getStatusCode(),errorMessage:t.getErrorMessage(),events:r.map(function(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})},o})})}catch(e){return Promise.reject(e)}}(e,s);case t.isScript(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.ExecuteScriptAtLatestBlockRequest,a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return s.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(e.arguments[t].asArgument))}),s.setScript(a),Promise.resolve(c(t.node,r.AccessAPI.ExecuteScriptAtLatestBlock,s)).then(function(t){var r=n.response();return r.tag=e.tag,r.encodedData=JSON.parse(Buffer.from(t.getValue_asU8()).toString("utf8")),r})})}catch(e){return Promise.reject(e)}}(e,s);case t.isGetAccount(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(s){e=s;var a,i=new r.GetAccountRequest;return i.setAddress((a=o.sansPrefix(e.accountAddr),Buffer.from(a.padStart(16,0),"hex"))),Promise.resolve(c(t.node,r.AccessAPI.GetAccount,i)).then(function(t){var r=n.response();r.tag=e.tag;var s=t.getAccount();return r.account={address:o.withPrefix(l(s.getAddress_asU8())),balance:s.getBalance(),code:s.getCode_asU8(),keys:s.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:l(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},r})})}catch(e){return Promise.reject(e)}}(e,s);case t.isGetEvents(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.GetEventsForHeightRangeRequest;return s.setType(e.events.eventType),s.setStartHeight(Number(e.events.start)),s.setEndHeight(Number(e.events.end)),Promise.resolve(c(t.node,r.AccessAPI.GetEventsForHeightRange,s)).then(function(t){var r=n.response();r.tag=e.tag;var o=t.getResultsList();return r.events=o.reduce(function(e,t){var r=t.getBlockId(),n=t.getBlockHeight();return t.getEventsList().forEach(function(t){var o;e.push({blockId:r,blockHeight:n,type:t.getType(),transactionId:(o=t.getTransactionId_asU8(),Buffer.from(o).toString("hex")),transactionIndex:t.getTransactionIndex(),eventIndex:t.getEventIndex(),payload:JSON.parse(Buffer.from(t.getPayload_asU8()).toString("utf8"))})}),e},[]),r})})}catch(e){return Promise.reject(e)}}(e,s);case t.isGetLatestBlock(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.GetLatestBlockRequest;return e.latestBlock&&e.latestBlock.isSealed&&(s.setIsSealed(e.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;")),e.block&&e.block.isSealed&&s.setIsSealed(e.block.isSealed),Promise.resolve(c(t.node,r.AccessAPI.GetLatestBlock,s)).then(function(t){var r=t.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),a=r.getSignaturesList(),i=n.response();return i.tag=e.tag,i.block={id:f(r.getId_asU8()),parentId:f(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:f(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:f(e.getBlockId_asU8()),executionReceiptId:f(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(e,s);case t.isGetBlockById(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.GetBlockByIDRequest;return s.setId(Buffer.from(e.block.id,"hex")),Promise.resolve(c(t.node,r.AccessAPI.GetBlockByID,s)).then(function(t){var r=t.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),a=r.getSignaturesList(),i=n.response();return i.tag=e.tag,i.block={id:d(r.getId_asU8()),parentId:d(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:d(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:d(e.getBlockId_asU8()),executionReceiptId:d(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(e,s);case t.isGetBlockByHeight(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.GetBlockByHeightRequest;return s.setHeight(e.block.height),Promise.resolve(c(t.node,r.AccessAPI.GetBlockByHeight,s)).then(function(t){var r=t.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),a=r.getSignaturesList(),i=n.response();return i.tag=e.tag,i.block={id:p(r.getId_asU8()),parentId:p(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:p(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:p(e.getBlockId_asU8()),executionReceiptId:p(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(e,s);case t.isPing(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.PingRequest;return Promise.resolve(c(t.node,r.AccessAPI.Ping,s)).then(function(t){var r=n.response();return r.tag=e.tag,r})})}catch(e){return Promise.reject(e)}}(e,s);default:return e}})},m=s.node;return Promise.resolve(m?a(m):Promise.resolve(i.config().get("accessNode.api")).then(a))}catch(e){return Promise.reject(e)}}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@onflow/interaction"),require("@onflow/protobuf"),require("@onflow/response"),require("@onflow/util-address"),require("@improbable-eng/grpc-web"),require("@improbable-eng/grpc-web-node-http-transport"),require("@onflow/config")):"function"==typeof define&&define.amd?define(["exports","@onflow/interaction","@onflow/protobuf","@onflow/response","@onflow/util-address","@improbable-eng/grpc-web","@improbable-eng/grpc-web-node-http-transport","@onflow/config"],t):t((e=e||self).send={},e.interaction,e.protobuf,e.response,e.utilAddress,e.grpcWeb,e.grpcWebNodeHttpTransport,e.config)}(this,function(e,t,r,n,o,s,a,i){var c=function(e,t,r){try{return Promise.resolve(new Promise(function(n,o){s.grpc.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===s.grpc.Code.OK?n(e.message):o(new Error(t))}})}))}catch(e){return Promise.reject(e)}};s.grpc.setDefaultTransport(a.NodeHttpTransport());var u=function(e){return Buffer.from(e,"hex")},g=function(e){return Buffer.from(e.padStart(16,0),"hex")},l=function(e){return Buffer.from(e).toString("hex")},f=function(e){return Buffer.from(e).toString("hex")},d=function(e){return Buffer.from(e).toString("hex")},p=function(e){return Buffer.from(e).toString("hex")};e.send=function(e,s){void 0===s&&(s={});try{var a=function(a){return s.node=a,Promise.resolve(e).then(function(a){switch(e=a,!0){case t.isTransaction(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(s){e=s;var a=new r.Transaction;a.setScript(Buffer.from(e.message.cadence,"utf8")),a.setGasLimit(e.message.computeLimit),a.setReferenceBlockId(e.message.refBlock?u(e.message.refBlock):null),a.setPayer(g(o.sansPrefix(e.accounts[e.payer].addr))),e.message.arguments.forEach(function(t){return a.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(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 a.addAuthorizers(g(o.sansPrefix(e)))});var i=new r.Transaction.ProposalKey;i.setAddress(g(o.sansPrefix(e.accounts[e.proposer].addr))),i.setKeyId(e.accounts[e.proposer].keyId),i.setSequenceNumber(e.accounts[e.proposer].sequenceNum),a.setProposalKey(i);for(var l=0,f=Object.values(e.accounts);l<f.length;l++){var d=f[l];try{if(null==d.signature)return;if(d.role.payer)return;var p=new r.Transaction.Signature;p.setAddress(g(o.sansPrefix(d.addr))),p.setKeyId(d.keyId),p.setSignature(u(d.signature)),a.addPayloadSignatures(p)}catch(t){throw console.error("Trouble applying payload signature",{acct:d,ix:e}),t}}for(var m=0,h=Object.values(e.accounts);m<h.length;m++){var v=h[m];try{if(null==v.signature)return;if(!v.role.payer)return;var S=new r.Transaction.Signature;S.setAddress(g(o.sansPrefix(v.addr))),S.setKeyId(v.keyId),S.setSignature(u(v.signature)),a.addEnvelopeSignatures(S)}catch(t){throw console.error("Trouble applying envelope signature",{acct:v,ix:e}),t}}var I=new r.SendTransactionRequest;return I.setTransaction(a),console.log("UNARY_SEND",{req:I}),Promise.resolve(c(t.node,r.AccessAPI.SendTransaction,I)).then(function(t){console.log("UNARY_SENT",{res:t});var r,o=n.response();return o.tag=e.tag,o.transactionId=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),console.log("SEND TX COMPLETE",{ret:o}),o})})}catch(e){return Promise.reject(e)}}(e,s);case t.isGetTransactionStatus(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.GetTransactionRequest;return s.setId(Buffer.from(e.transactionId,"hex")),Promise.resolve(c(t.node,r.AccessAPI.GetTransactionResult,s)).then(function(t){var r=t.getEventsList(),o=n.response();return o.tag=e.tag,o.transaction={status:t.getStatus(),statusCode:t.getStatusCode(),errorMessage:t.getErrorMessage(),events:r.map(function(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})},o})})}catch(e){return Promise.reject(e)}}(e,s);case t.isScript(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.ExecuteScriptAtLatestBlockRequest,a=Buffer.from(e.message.cadence,"utf8");return e.message.arguments.forEach(function(t){return s.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(e.arguments[t].asArgument))}),s.setScript(a),Promise.resolve(c(t.node,r.AccessAPI.ExecuteScriptAtLatestBlock,s)).then(function(t){var r=n.response();return r.tag=e.tag,r.encodedData=JSON.parse(Buffer.from(t.getValue_asU8()).toString("utf8")),r})})}catch(e){return Promise.reject(e)}}(e,s);case t.isGetAccount(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(s){e=s;var a,i=new r.GetAccountRequest;return i.setAddress((a=o.sansPrefix(e.accountAddr),Buffer.from(a.padStart(16,0),"hex"))),Promise.resolve(c(t.node,r.AccessAPI.GetAccount,i)).then(function(t){var r=n.response();r.tag=e.tag;var s=t.getAccount();return r.account={address:o.withPrefix(l(s.getAddress_asU8())),balance:s.getBalance(),code:s.getCode_asU8(),keys:s.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:l(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},r})})}catch(e){return Promise.reject(e)}}(e,s);case t.isGetEvents(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.GetEventsForHeightRangeRequest;return s.setType(e.events.eventType),s.setStartHeight(Number(e.events.start)),s.setEndHeight(Number(e.events.end)),Promise.resolve(c(t.node,r.AccessAPI.GetEventsForHeightRange,s)).then(function(t){var r=n.response();r.tag=e.tag;var o=t.getResultsList();return r.events=o.reduce(function(e,t){var r=t.getBlockId(),n=t.getBlockHeight();return t.getEventsList().forEach(function(t){var o;e.push({blockId:r,blockHeight:n,type:t.getType(),transactionId:(o=t.getTransactionId_asU8(),Buffer.from(o).toString("hex")),transactionIndex:t.getTransactionIndex(),eventIndex:t.getEventIndex(),payload:JSON.parse(Buffer.from(t.getPayload_asU8()).toString("utf8"))})}),e},[]),r})})}catch(e){return Promise.reject(e)}}(e,s);case t.isGetLatestBlock(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.GetLatestBlockRequest;return e.latestBlock&&e.latestBlock.isSealed&&(s.setIsSealed(e.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;")),e.block&&e.block.isSealed&&s.setIsSealed(e.block.isSealed),Promise.resolve(c(t.node,r.AccessAPI.GetLatestBlock,s)).then(function(t){var r=t.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),a=r.getSignaturesList(),i=n.response();return i.tag=e.tag,i.block={id:f(r.getId_asU8()),parentId:f(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:f(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:f(e.getBlockId_asU8()),executionReceiptId:f(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(e,s);case t.isGetBlockById(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.GetBlockByIDRequest;return s.setId(Buffer.from(e.block.id,"hex")),Promise.resolve(c(t.node,r.AccessAPI.GetBlockByID,s)).then(function(t){var r=t.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),a=r.getSignaturesList(),i=n.response();return i.tag=e.tag,i.block={id:d(r.getId_asU8()),parentId:d(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:d(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:d(e.getBlockId_asU8()),executionReceiptId:d(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(e,s);case t.isGetBlockByHeight(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.GetBlockByHeightRequest;return s.setHeight(e.block.height),Promise.resolve(c(t.node,r.AccessAPI.GetBlockByHeight,s)).then(function(t){var r=t.getBlock(),o=r.getCollectionGuaranteesList(),s=r.getBlockSealsList(),a=r.getSignaturesList(),i=n.response();return i.tag=e.tag,i.block={id:p(r.getId_asU8()),parentId:p(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:p(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.map(function(e){return{blockId:p(e.getBlockId_asU8()),executionReceiptId:p(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(e,s);case t.isPing(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.PingRequest;return Promise.resolve(c(t.node,r.AccessAPI.Ping,s)).then(function(t){var r=n.response();return r.tag=e.tag,r})})}catch(e){return Promise.reject(e)}}(e,s);default:return e}})},m=s.node;return Promise.resolve(m?a(m):Promise.resolve(i.config().get("accessNode.api")).then(a))}catch(e){return Promise.reject(e)}}});
//# sourceMappingURL=send.umd.js.map
{
"name": "@onflow/send",
"version": "0.0.24",
"version": "0.0.25",
"description": "Flow SDK Send",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

@@ -86,3 +86,5 @@ import {AccessAPI, Transaction, SendTransactionRequest} from "@onflow/protobuf"

console.log("UNARY_SEND", {req})
const res = await unary(opts.node, AccessAPI.SendTransaction, req)
console.log("UNARY_SENT", {res})

@@ -89,0 +91,0 @@ let ret = response()

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc