@onflow/send
Advanced tools
Comparing version 0.0.22 to 0.0.23
@@ -5,2 +5,9 @@ ### Unreleased | ||
### 0.0.23 - 2020-12-03 | ||
- 2020-12-03 -- FIX modified how tx signatures were applied to gRPC call. | ||
- 2020-12-03 -- Sanitization of addresses of prefix when sending transactions. | ||
- 2020-12-03 -- Sanitization of addresses of prefix when sending getAccount. | ||
- 2020-12-03 -- Decoration of addresses of received getAccount data. | ||
### 0.0.22 - 2020-09-29 | ||
@@ -7,0 +14,0 @@ |
@@ -1,2 +0,2 @@ | ||
var e=require("@onflow/interaction"),t=require("@onflow/protobuf"),r=require("@onflow/response"),n=require("@improbable-eng/grpc-web"),s=require("@improbable-eng/grpc-web-node-http-transport"),o=require("@onflow/config"),a=function(e,t,r){try{return Promise.resolve(new Promise(function(s,o){n.grpc.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===n.grpc.Code.OK?s(e.message):o(new Error(t))}})}))}catch(e){return Promise.reject(e)}};n.grpc.setDefaultTransport(s.NodeHttpTransport());var i=function(e){return Buffer.from(e,"hex")},c=function(e){return Buffer.from(e.padStart(16,0),"hex")},u=function(e){return Buffer.from(e).toString("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")};exports.send=function(n,s){void 0===s&&(s={});try{var f=function(o){return s.node=o,Promise.resolve(n).then(function(o){switch(n=o,!0){case e.isTransaction(n):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.Transaction;o.setScript(Buffer.from(e.message.cadence,"utf8")),o.setGasLimit(e.message.computeLimit),o.setReferenceBlockId(e.message.refBlock?i(e.message.refBlock):null),o.setPayer(c(e.accounts[e.payer].addr)),e.message.arguments.forEach(function(t){return o.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(e.arguments[t].asArgument))}),e.authorizations.forEach(function(t){return o.addAuthorizers(c(e.accounts[t].addr))});var u=new t.Transaction.ProposalKey;u.setAddress(c(e.accounts[e.proposer].addr)),u.setKeyId(e.accounts[e.proposer].keyId),u.setSequenceNumber(e.accounts[e.proposer].sequenceNum),o.setProposalKey(u),e.authorizations.forEach(function(r){if(null!==e.accounts[r].signature&&!e.accounts[r].role.payer){var n=new t.Transaction.Signature;n.setAddress(c(e.accounts[r].addr)),n.setKeyId(e.accounts[r].keyId),n.setSignature(i(e.accounts[r].signature)),o.addPayloadSignatures(n)}});var g=new t.Transaction.Signature;g.setAddress(c(e.accounts[e.payer].addr)),g.setKeyId(e.accounts[e.payer].keyId),g.setSignature(i(e.accounts[e.payer].signature)),o.addEnvelopeSignatures(g);var l=new t.SendTransactionRequest;return l.setTransaction(o),Promise.resolve(a(n.node,t.AccessAPI.SendTransaction,l)).then(function(t){var n,s=r.response();return s.tag=e.tag,s.transactionId=(n=t.getId_asU8(),Buffer.from(n).toString("hex")),s})})}catch(e){return Promise.reject(e)}}(n,s);case e.isGetTransactionStatus(n):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(a(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)}}(n,s);case e.isScript(n):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.ExecuteScriptAtLatestBlockRequest,i=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(i),Promise.resolve(a(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)}}(n,s);case e.isGetAccount(n):return function(e,n){void 0===n&&(n={});try{return Promise.resolve(e).then(function(s){e=s;var o=new t.GetAccountRequest;return o.setAddress(Buffer.from(e.accountAddr.padStart(16,0),"hex")),Promise.resolve(a(n.node,t.AccessAPI.GetAccount,o)).then(function(t){var n=r.response();n.tag=e.tag;var s=t.getAccount();return n.account={address:u(s.getAddress_asU8()),balance:s.getBalance(),code:s.getCode_asU8(),keys:s.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:u(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},n})})}catch(e){return Promise.reject(e)}}(n,s);case e.isGetEvents(n):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(a(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)}}(n,s);case e.isGetLatestBlock(n):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(a(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:g(n.getId_asU8()),parentId:g(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(function(e){return{collectionId:g(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:g(e.getBlockId_asU8()),executionReceiptId:g(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},i})})}catch(e){return Promise.reject(e)}}(n,s);case e.isGetBlockById(n):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(a(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: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)}}(n,s);case e.isGetBlockByHeight(n):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(a(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: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)}}(n,s);case e.isPing(n):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(a(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)}}(n,s);default:return n}})},p=s.node;return Promise.resolve(p?f(p):Promise.resolve(o.config().get("accessNode.api")).then(f))}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];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)}for(var m=0,v=Object.values(e.accounts);m<v.length;m++){var h=v[m];if(null==h.signature)return;if(!h.role.payer)return;var I=new t.Transaction.Signature;I.setAddress(u(n.sansPrefix(h.addr))),I.setKeyId(h.keyId),I.setSignature(c(h.signature)),a.addEnvelopeSignatures(I)}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")),"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("FLOW::TX",{details:{txId:s.transactionId}})),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 c,isTransaction as i}from"@onflow/interaction";import{Transaction as g,SendTransactionRequest as u,AccessAPI as d,GetTransactionRequest as l,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{grpc as k}from"@improbable-eng/grpc-web";import{NodeHttpTransport as B}from"@improbable-eng/grpc-web-node-http-transport";import{config as b}from"@onflow/config";async function x(e,t,a){return new Promise((n,s)=>{k.unary(t,{request:a,host:e,onEnd:({status:e,statusMessage:t,message:a})=>{e===k.Code.OK?n(a):s(new Error(t))}})})}k.setDefaultTransport(B());const L=e=>Buffer.from(e,"hex"),A=e=>Buffer.from(e.padStart(16,0),"hex"),U=e=>Buffer.from(e).toString("hex"),_=e=>Buffer.from(e).toString("hex"),v=e=>Buffer.from(e).toString("hex"),E=e=>Buffer.from(e).toString("hex"),R=async(k,B={})=>{switch(B.node=B.node||await b().get("accessNode.api"),k=await k,!0){case i(k):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(A(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.forEach(t=>a.addAuthorizers(A(e.accounts[t].addr)));const n=new g.ProposalKey;n.setAddress(A(e.accounts[e.proposer].addr)),n.setKeyId(e.accounts[e.proposer].keyId),n.setSequenceNumber(e.accounts[e.proposer].sequenceNum),a.setProposalKey(n),e.authorizations.forEach(t=>{if(null===e.accounts[t].signature||e.accounts[t].role.payer)return;const n=new g.Signature;n.setAddress(A(e.accounts[t].addr)),n.setKeyId(e.accounts[t].keyId),n.setSignature(L(e.accounts[t].signature)),a.addPayloadSignatures(n)});const s=new g.Signature;s.setAddress(A(e.accounts[e.payer].addr)),s.setKeyId(e.accounts[e.payer].keyId),s.setSignature(L(e.accounts[e.payer].signature)),a.addEnvelopeSignatures(s);const o=new u;o.setTransaction(a);const r=await x(t.node,d.SendTransaction,o);let c=y();var i;return c.tag=e.tag,c.transactionId=(i=r.getId_asU8(),Buffer.from(i).toString("hex")),c}(k,B);case c(k):return async function(e,t={}){e=await e;const a=new l;a.setId(Buffer.from(e.transactionId,"hex"));const n=await x(t.node,d.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}(k,B);case r(k):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 x(t.node,d.ExecuteScriptAtLatestBlock,a);let o=y();return o.tag=e.tag,o.encodedData=JSON.parse(Buffer.from(s.getValue_asU8()).toString("utf8")),o}(k,B);case o(k):return async function(e,t={}){e=await e;const a=new p;a.setAddress(Buffer.from(e.accountAddr.padStart(16,0),"hex"));const n=await x(t.node,d.GetAccount,a);let s=y();s.tag=e.tag;const o=n.getAccount();return s.account={address:U(o.getAddress_asU8()),balance:o.getBalance(),code:o.getCode_asU8(),keys:o.getKeysList().map(e=>({index:e.getIndex(),publicKey:U(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}))},s}(k,B);case s(k):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 x(t.node,d.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}(k,B);case n(k):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 x(t.node,d.GetLatestBlock,a)).getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),r=n.getSignaturesList(),c=y();return c.tag=e.tag,c.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},c}(k,B);case a(k):return async function(e,t={}){e=await e;const a=new I;a.setId(Buffer.from(e.block.id,"hex"));const n=(await x(t.node,d.GetBlockByID,a)).getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),r=n.getSignaturesList(),c=y();return c.tag=e.tag,c.block={id:v(n.getId_asU8()),parentId:v(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(e=>({collectionId:v(e.getCollectionId_asU8()),signatures:e.getSignaturesList()})),blockSeals:o.map(e=>({blockId:v(e.getBlockId_asU8()),executionReceiptId:v(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:r},c}(k,B);case t(k):return async function(e,t={}){e=await e;const a=new h;a.setHeight(e.block.height);const n=(await x(t.node,d.GetBlockByHeight,a)).getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),r=n.getSignaturesList(),c=y();return c.tag=e.tag,c.block={id:E(n.getId_asU8()),parentId:E(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(e=>({collectionId:E(e.getCollectionId_asU8()),signatures:e.getSignaturesList()})),blockSeals:o.map(e=>({blockId:E(e.getBlockId_asU8()),executionReceiptId:E(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()})),signatures:r},c}(k,B);case e(k):return async function(e,t={}){e=await e;const a=new w;await x(t.node,d.Ping,a);let n=y();return n.tag=e.tag,n}(k,B);default:return k}};export{R 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 d,GetTransactionRequest as l,ExecuteScriptAtLatestBlockRequest as f,GetAccountRequest as p,GetEventsForHeightRangeRequest as m,GetLatestBlockRequest as S,GetBlockByIDRequest as I,GetBlockByHeightRequest as w,PingRequest as h}from"@onflow/protobuf";import{response as k}from"@onflow/response";import{sansPrefix as y,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"),U=e=>Buffer.from(e.padStart(16,0),"hex"),_=e=>Buffer.from(e).toString("hex"),E=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(U(y(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(U(y(e))));const n=new g.ProposalKey;n.setAddress(U(y(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)){if(null==t.signature)continue;if(t.role.payer)continue;const e=new g.Signature;e.setAddress(U(y(t.addr))),e.setKeyId(t.keyId),e.setSignature(A(t.signature)),a.addPayloadSignatures(e)}for(let t of Object.values(e.accounts)){if(null==t.signature)continue;if(!t.role.payer)continue;const e=new g.Signature;e.setAddress(U(y(t.addr))),e.setKeyId(t.keyId),e.setSignature(A(t.signature)),a.addEnvelopeSignatures(e)}const s=new u;s.setTransaction(a);const o=await L(t.node,d.SendTransaction,s);let r=k();var i;return r.tag=e.tag,r.transactionId=(i=o.getId_asU8(),Buffer.from(i).toString("hex")),"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("FLOW::TX",{details:{txId:r.transactionId}})),r}(b,x);case i(b):return async function(e,t={}){e=await e;const a=new l;a.setId(Buffer.from(e.transactionId,"hex"));const n=await L(t.node,d.GetTransactionResult,a);let s=n.getEventsList(),o=k();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,d.ExecuteScriptAtLatestBlock,a);let o=k();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=y(e.accountAddr),Buffer.from(n.padStart(16,0),"hex")));const s=await L(t.node,d.GetAccount,a);let o=k();o.tag=e.tag;const r=s.getAccount();return o.account={address:B(_(r.getAddress_asU8())),balance:r.getBalance(),code:r.getCode_asU8(),keys:r.getKeysList().map(e=>({index:e.getIndex(),publicKey:_(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,d.GetEventsForHeightRange,a);let s=k();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,d.GetLatestBlock,a)).getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),r=n.getSignaturesList(),i=k();return i.tag=e.tag,i.block={id:E(n.getId_asU8()),parentId:E(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(e=>({collectionId:E(e.getCollectionId_asU8()),signatures:e.getSignaturesList()})),blockSeals:o.map(e=>({blockId:E(e.getBlockId_asU8()),executionReceiptId:E(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,d.GetBlockByID,a)).getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),r=n.getSignaturesList(),i=k();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 w;a.setHeight(e.block.height);const n=(await L(t.node,d.GetBlockByHeight,a)).getBlock(),s=n.getCollectionGuaranteesList(),o=n.getBlockSealsList(),r=n.getSignaturesList(),i=k();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 h;await L(t.node,d.Ping,a);let n=k();return n.tag=e.tag,n}(b,x);default:return b}};export{N 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 d,ExecuteScriptAtLatestBlockRequest as f,GetAccountRequest as m,GetEventsForHeightRangeRequest as p,GetLatestBlockRequest as h,GetBlockByIDRequest as v,GetBlockByHeightRequest as S,PingRequest as I}from"@onflow/protobuf";import{response as y}from"@onflow/response";import{grpc as k}from"@improbable-eng/grpc-web";import{NodeHttpTransport as B}from"@improbable-eng/grpc-web-node-http-transport";import{config as P}from"@onflow/config";var b=function(e,t,r){try{return Promise.resolve(new Promise(function(n,o){k.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===k.Code.OK?n(e.message):o(new Error(t))}})}))}catch(e){return Promise.reject(e)}};k.setDefaultTransport(B());var x=function(e){return Buffer.from(e,"hex")},w=function(e){return Buffer.from(e.padStart(16,0),"hex")},L=function(e){return Buffer.from(e).toString("hex")},A=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")},E=function(k,B){void 0===B&&(B={});try{var E=function(P){return B.node=P,Promise.resolve(k).then(function(P){switch(k=P,!0){case u(k):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?x(e.message.refBlock):null),n.setPayer(w(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.forEach(function(t){return n.addAuthorizers(w(e.accounts[t].addr))});var o=new c.ProposalKey;o.setAddress(w(e.accounts[e.proposer].addr)),o.setKeyId(e.accounts[e.proposer].keyId),o.setSequenceNumber(e.accounts[e.proposer].sequenceNum),n.setProposalKey(o),e.authorizations.forEach(function(t){if(null!==e.accounts[t].signature&&!e.accounts[t].role.payer){var r=new c.Signature;r.setAddress(w(e.accounts[t].addr)),r.setKeyId(e.accounts[t].keyId),r.setSignature(x(e.accounts[t].signature)),n.addPayloadSignatures(r)}});var s=new c.Signature;s.setAddress(w(e.accounts[e.payer].addr)),s.setKeyId(e.accounts[e.payer].keyId),s.setSignature(x(e.accounts[e.payer].signature)),n.addEnvelopeSignatures(s);var a=new g;return a.setTransaction(n),Promise.resolve(b(t.node,l.SendTransaction,a)).then(function(t){var r,n=y();return n.tag=e.tag,n.transactionId=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),n})})}catch(e){return Promise.reject(e)}}(k,B);case i(k):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new d;return n.setId(Buffer.from(e.transactionId,"hex")),Promise.resolve(b(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)}}(k,B);case a(k):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new f,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(b(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)}}(k,B);case s(k):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new m;return n.setAddress(Buffer.from(e.accountAddr.padStart(16,0),"hex")),Promise.resolve(b(t.node,l.GetAccount,n)).then(function(t){var r=y();r.tag=e.tag;var n=t.getAccount();return r.account={address:L(n.getAddress_asU8()),balance:n.getBalance(),code:n.getCode_asU8(),keys:n.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)}}(k,B);case o(k):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(b(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)}}(k,B);case n(k):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new h;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(b(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:A(r.getId_asU8()),parentId:A(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:A(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:A(e.getBlockId_asU8()),executionReceiptId:A(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:s},a})})}catch(e){return Promise.reject(e)}}(k,B);case r(k):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new v;return n.setId(Buffer.from(e.block.id,"hex")),Promise.resolve(b(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: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)}}(k,B);case t(k):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(b(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.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)}}(k,B);case e(k):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(b(t.node,l.Ping,n)).then(function(t){var r=y();return r.tag=e.tag,r})})}catch(e){return Promise.reject(e)}}(k,B);default:return k}})},R=B.node;return Promise.resolve(R?E(R):Promise.resolve(P().get("accessNode.api")).then(E))}catch(e){return Promise.reject(e)}};export{E 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 d,ExecuteScriptAtLatestBlockRequest as f,GetAccountRequest as m,GetEventsForHeightRangeRequest as p,GetLatestBlockRequest as v,GetBlockByIDRequest as h,GetBlockByHeightRequest as S,PingRequest as I}from"@onflow/protobuf";import{response as k}from"@onflow/response";import{sansPrefix as y,withPrefix as B}from"@onflow/util-address";import{grpc as P}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){P.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===P.Code.OK?n(e.message):o(new Error(t))}})}))}catch(e){return Promise.reject(e)}};P.setDefaultTransport(b());var L=function(e){return Buffer.from(e,"hex")},A=function(e){return Buffer.from(e.padStart(16,0),"hex")},U=function(e){return Buffer.from(e).toString("hex")},_=function(e){return Buffer.from(e).toString("hex")},E=function(e){return Buffer.from(e).toString("hex")},R=function(e){return Buffer.from(e).toString("hex")},T=function(P,b){void 0===b&&(b={});try{var T=function(x){return b.node=x,Promise.resolve(P).then(function(x){switch(P=x,!0){case u(P):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(y(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(y(e)))});var o=new c.ProposalKey;o.setAddress(A(y(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];if(null==i.signature)return;if(i.role.payer)return;var u=new c.Signature;u.setAddress(A(y(i.addr))),u.setKeyId(i.keyId),u.setSignature(L(i.signature)),n.addPayloadSignatures(u)}for(var d=0,f=Object.values(e.accounts);d<f.length;d++){var m=f[d];if(null==m.signature)return;if(!m.role.payer)return;var p=new c.Signature;p.setAddress(A(y(m.addr))),p.setKeyId(m.keyId),p.setSignature(L(m.signature)),n.addEnvelopeSignatures(p)}var v=new g;return v.setTransaction(n),Promise.resolve(w(t.node,l.SendTransaction,v)).then(function(t){var r,n=k();return n.tag=e.tag,n.transactionId=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("FLOW::TX",{details:{txId:n.transactionId}})),n})})}catch(e){return Promise.reject(e)}}(P,b);case i(P):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new d;return n.setId(Buffer.from(e.transactionId,"hex")),Promise.resolve(w(t.node,l.GetTransactionResult,n)).then(function(t){var r=t.getEventsList(),n=k();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)}}(P,b);case a(P):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(r){e=r;var n=new f,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=k();return r.tag=e.tag,r.encodedData=JSON.parse(Buffer.from(t.getValue_asU8()).toString("utf8")),r})})}catch(e){return Promise.reject(e)}}(P,b);case s(P):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=y(e.accountAddr),Buffer.from(n.padStart(16,0),"hex"))),Promise.resolve(w(t.node,l.GetAccount,o)).then(function(t){var r=k();r.tag=e.tag;var n=t.getAccount();return r.account={address:B(U(n.getAddress_asU8())),balance:n.getBalance(),code:n.getCode_asU8(),keys:n.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:U(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},r})})}catch(e){return Promise.reject(e)}}(P,b);case o(P):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=k();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)}}(P,b);case n(P):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=k();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)}}(P,b);case r(P):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=k();return a.tag=e.tag,a.block={id:E(r.getId_asU8()),parentId:E(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:E(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:E(e.getBlockId_asU8()),executionReceiptId:E(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:s},a})})}catch(e){return Promise.reject(e)}}(P,b);case t(P):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=k();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)}}(P,b);case e(P):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=k();return r.tag=e.tag,r})})}catch(e){return Promise.reject(e)}}(P,b);default:return P}})},j=b.node;return Promise.resolve(j?T(j):Promise.resolve(x().get("accessNode.api")).then(T))}catch(e){return Promise.reject(e)}};export{T 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("@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","@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.grpcWeb,e.grpcWebNodeHttpTransport,e.config)}(this,function(e,t,r,n,o,s,a){var i=function(e,t,r){try{return Promise.resolve(new Promise(function(n,s){o.grpc.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===o.grpc.Code.OK?n(e.message):s(new Error(t))}})}))}catch(e){return Promise.reject(e)}};o.grpc.setDefaultTransport(s.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")};e.send=function(e,o){void 0===o&&(o={});try{var s=function(s){return o.node=s,Promise.resolve(e).then(function(s){switch(e=s,!0){case t.isTransaction(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.Transaction;s.setScript(Buffer.from(e.message.cadence,"utf8")),s.setGasLimit(e.message.computeLimit),s.setReferenceBlockId(e.message.refBlock?c(e.message.refBlock):null),s.setPayer(u(e.accounts[e.payer].addr)),e.message.arguments.forEach(function(t){return s.addArguments(function(e){return Buffer.from(JSON.stringify(e),"utf8")}(e.arguments[t].asArgument))}),e.authorizations.forEach(function(t){return s.addAuthorizers(u(e.accounts[t].addr))});var a=new r.Transaction.ProposalKey;a.setAddress(u(e.accounts[e.proposer].addr)),a.setKeyId(e.accounts[e.proposer].keyId),a.setSequenceNumber(e.accounts[e.proposer].sequenceNum),s.setProposalKey(a),e.authorizations.forEach(function(t){if(null!==e.accounts[t].signature&&!e.accounts[t].role.payer){var n=new r.Transaction.Signature;n.setAddress(u(e.accounts[t].addr)),n.setKeyId(e.accounts[t].keyId),n.setSignature(c(e.accounts[t].signature)),s.addPayloadSignatures(n)}});var g=new r.Transaction.Signature;g.setAddress(u(e.accounts[e.payer].addr)),g.setKeyId(e.accounts[e.payer].keyId),g.setSignature(c(e.accounts[e.payer].signature)),s.addEnvelopeSignatures(g);var l=new r.SendTransactionRequest;return l.setTransaction(s),Promise.resolve(i(t.node,r.AccessAPI.SendTransaction,l)).then(function(t){var r,o=n.response();return o.tag=e.tag,o.transactionId=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),o})})}catch(e){return Promise.reject(e)}}(e,o);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(i(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,o);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(i(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,o);case t.isGetAccount(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var s=new r.GetAccountRequest;return s.setAddress(Buffer.from(e.accountAddr.padStart(16,0),"hex")),Promise.resolve(i(t.node,r.AccessAPI.GetAccount,s)).then(function(t){var r=n.response();r.tag=e.tag;var o=t.getAccount();return r.account={address: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()}})},r})})}catch(e){return Promise.reject(e)}}(e,o);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(i(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,o);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(i(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:l(r.getId_asU8()),parentId:l(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:l(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:s.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)}}(e,o);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(i(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,o);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(i(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: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,o);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(i(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,o);default:return e}})},p=o.node;return Promise.resolve(p?s(p):Promise.resolve(a.config().get("accessNode.api")).then(s))}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,s,o,a,i){var c=function(e,t,r){try{return Promise.resolve(new Promise(function(n,s){o.grpc.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===o.grpc.Code.OK?n(e.message):s(new Error(t))}})}))}catch(e){return Promise.reject(e)}};o.grpc.setDefaultTransport(a.NodeHttpTransport());var u=function(e){return Buffer.from(e,"hex")},g=function(e){return Buffer.from(e.padStart(16,0),"hex")},f=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")},p=function(e){return Buffer.from(e).toString("hex")};e.send=function(e,o){void 0===o&&(o={});try{var a=function(a){return o.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(o){e=o;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(s.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(s.sansPrefix(e)))});var i=new r.Transaction.ProposalKey;i.setAddress(g(s.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 f=0,l=Object.values(e.accounts);f<l.length;f++){var d=l[f];if(null==d.signature)return;if(d.role.payer)return;var p=new r.Transaction.Signature;p.setAddress(g(s.sansPrefix(d.addr))),p.setKeyId(d.keyId),p.setSignature(u(d.signature)),a.addPayloadSignatures(p)}for(var m=0,v=Object.values(e.accounts);m<v.length;m++){var h=v[m];if(null==h.signature)return;if(!h.role.payer)return;var I=new r.Transaction.Signature;I.setAddress(g(s.sansPrefix(h.addr))),I.setKeyId(h.keyId),I.setSignature(u(h.signature)),a.addEnvelopeSignatures(I)}var S=new r.SendTransactionRequest;return S.setTransaction(a),Promise.resolve(c(t.node,r.AccessAPI.SendTransaction,S)).then(function(t){var r,s=n.response();return s.tag=e.tag,s.transactionId=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),"undefined"!=typeof window&&window.dispatchEvent(new CustomEvent("FLOW::TX",{details:{txId:s.transactionId}})),s})})}catch(e){return Promise.reject(e)}}(e,o);case t.isGetTransactionStatus(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(s){e=s;var o=new r.GetTransactionRequest;return o.setId(Buffer.from(e.transactionId,"hex")),Promise.resolve(c(t.node,r.AccessAPI.GetTransactionResult,o)).then(function(t){var r=t.getEventsList(),s=n.response();return s.tag=e.tag,s.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})},s})})}catch(e){return Promise.reject(e)}}(e,o);case t.isScript(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(s){e=s;var o=new r.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(c(t.node,r.AccessAPI.ExecuteScriptAtLatestBlock,o)).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,o);case t.isGetAccount(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(o){e=o;var a,i=new r.GetAccountRequest;return i.setAddress((a=s.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 o=t.getAccount();return r.account={address:s.withPrefix(f(o.getAddress_asU8())),balance:o.getBalance(),code:o.getCode_asU8(),keys:o.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:f(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},r})})}catch(e){return Promise.reject(e)}}(e,o);case t.isGetEvents(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(s){e=s;var o=new r.GetEventsForHeightRangeRequest;return o.setType(e.events.eventType),o.setStartHeight(Number(e.events.start)),o.setEndHeight(Number(e.events.end)),Promise.resolve(c(t.node,r.AccessAPI.GetEventsForHeightRange,o)).then(function(t){var r=n.response();r.tag=e.tag;var s=t.getResultsList();return r.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},[]),r})})}catch(e){return Promise.reject(e)}}(e,o);case t.isGetLatestBlock(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(s){e=s;var o=new r.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(c(t.node,r.AccessAPI.GetLatestBlock,o)).then(function(t){var r=t.getBlock(),s=r.getCollectionGuaranteesList(),o=r.getBlockSealsList(),a=r.getSignaturesList(),i=n.response();return i.tag=e.tag,i.block={id:l(r.getId_asU8()),parentId:l(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.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)}}(e,o);case t.isGetBlockById(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(s){e=s;var o=new r.GetBlockByIDRequest;return o.setId(Buffer.from(e.block.id,"hex")),Promise.resolve(c(t.node,r.AccessAPI.GetBlockByID,o)).then(function(t){var r=t.getBlock(),s=r.getCollectionGuaranteesList(),o=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: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)}}(e,o);case t.isGetBlockByHeight(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(s){e=s;var o=new r.GetBlockByHeightRequest;return o.setHeight(e.block.height),Promise.resolve(c(t.node,r.AccessAPI.GetBlockByHeight,o)).then(function(t){var r=t.getBlock(),s=r.getCollectionGuaranteesList(),o=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:s.map(function(e){return{collectionId:p(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.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,o);case t.isPing(e):return function(e,t){void 0===t&&(t={});try{return Promise.resolve(e).then(function(s){e=s;var o=new r.PingRequest;return Promise.resolve(c(t.node,r.AccessAPI.Ping,o)).then(function(t){var r=n.response();return r.tag=e.tag,r})})}catch(e){return Promise.reject(e)}}(e,o);default:return e}})},m=o.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.22", | ||
"version": "0.0.23", | ||
"description": "Flow SDK Send", | ||
@@ -30,3 +30,3 @@ "license": "Apache-2.0", | ||
"scripts": { | ||
"prepublishOnly": "npm test && npm run build", | ||
"prepublishOnly": "npm install && npm test && npm run build", | ||
"test": "jest", | ||
@@ -43,4 +43,5 @@ "build": "microbundle", | ||
"@onflow/protobuf": "0.1.6", | ||
"@onflow/response": "0.0.2" | ||
"@onflow/response": "0.0.2", | ||
"@onflow/util-address": "^0.0.0" | ||
} | ||
} |
import {GetAccountRequest, AccessAPI} from "@onflow/protobuf" | ||
import {response} from "@onflow/response" | ||
import {sansPrefix, withPrefix} from "@onflow/util-address" | ||
import {unary} from "./unary" | ||
@@ -15,3 +16,3 @@ | ||
const req = new GetAccountRequest() | ||
req.setAddress(addressBuffer(ix.accountAddr)) | ||
req.setAddress(addressBuffer(sansPrefix(ix.accountAddr))) | ||
@@ -25,3 +26,3 @@ const res = await unary(opts.node, AccessAPI.GetAccount, req) | ||
ret.account = { | ||
address: u8ToHex(account.getAddress_asU8()), | ||
address: withPrefix(u8ToHex(account.getAddress_asU8())), | ||
balance: account.getBalance(), | ||
@@ -28,0 +29,0 @@ code: account.getCode_asU8(), |
import {AccessAPI, Transaction, SendTransactionRequest} from "@onflow/protobuf" | ||
import {response} from "@onflow/response" | ||
import {sansPrefix} from "@onflow/util-address" | ||
import {unary} from "./unary" | ||
@@ -19,9 +20,20 @@ | ||
tx.setGasLimit(ix.message.computeLimit) | ||
tx.setReferenceBlockId(ix.message.refBlock ? hexBuffer(ix.message.refBlock) : null) | ||
tx.setPayer(addressBuffer(ix.accounts[ix.payer].addr)) | ||
ix.message.arguments.forEach(arg => tx.addArguments(argumentBuffer(ix.arguments[arg].asArgument))) | ||
ix.authorizations.forEach(tempId => tx.addAuthorizers(addressBuffer(ix.accounts[tempId].addr))) | ||
tx.setReferenceBlockId( | ||
ix.message.refBlock ? hexBuffer(ix.message.refBlock) : null | ||
) | ||
tx.setPayer(addressBuffer(sansPrefix(ix.accounts[ix.payer].addr))) | ||
ix.message.arguments.forEach(arg => | ||
tx.addArguments(argumentBuffer(ix.arguments[arg].asArgument)) | ||
) | ||
ix.authorizations | ||
.map(tempId => ix.accounts[tempId].addr) | ||
.reduce((prev, current) => { | ||
return prev.find(item => item === current) ? prev : [...prev, current] | ||
}, []) | ||
.forEach(addr => tx.addAuthorizers(addressBuffer(sansPrefix(addr)))) | ||
const proposalKey = new Transaction.ProposalKey() | ||
proposalKey.setAddress(addressBuffer(ix.accounts[ix.proposer].addr)) | ||
proposalKey.setAddress( | ||
addressBuffer(sansPrefix(ix.accounts[ix.proposer].addr)) | ||
) | ||
proposalKey.setKeyId(ix.accounts[ix.proposer].keyId) | ||
@@ -32,19 +44,32 @@ proposalKey.setSequenceNumber(ix.accounts[ix.proposer].sequenceNum) | ||
ix.authorizations.forEach(tempId => { | ||
if (ix.accounts[tempId].signature === null || ix.accounts[tempId].role.payer) return | ||
const authzSig = new Transaction.Signature() | ||
authzSig.setAddress(addressBuffer(ix.accounts[tempId].addr)) | ||
authzSig.setKeyId(ix.accounts[tempId].keyId) | ||
authzSig.setSignature(hexBuffer(ix.accounts[tempId].signature)) | ||
// Apply Non Payer Signatures to Payload Signatures | ||
for (let acct of Object.values(ix.accounts)) { | ||
if (acct.signature == null) continue // Skip -- No Signature | ||
if (acct.role.payer) continue // Skip -- Is Payer | ||
tx.addPayloadSignatures(authzSig) | ||
}) | ||
// Build Signature | ||
const sig = new Transaction.Signature() | ||
sig.setAddress(addressBuffer(sansPrefix(acct.addr))) | ||
sig.setKeyId(acct.keyId) | ||
sig.setSignature(hexBuffer(acct.signature)) | ||
const payerSig = new Transaction.Signature() | ||
payerSig.setAddress(addressBuffer(ix.accounts[ix.payer].addr)) | ||
payerSig.setKeyId(ix.accounts[ix.payer].keyId) | ||
payerSig.setSignature(hexBuffer(ix.accounts[ix.payer].signature)) | ||
// Apply Signature | ||
tx.addPayloadSignatures(sig) | ||
} | ||
tx.addEnvelopeSignatures(payerSig) | ||
// Apply Payer Signatures to Envelope Signatures | ||
for (let acct of Object.values(ix.accounts)) { | ||
if (acct.signature == null) continue // Skip -- No Signature | ||
if (!acct.role.payer) continue // Skip -- Not Payer | ||
// Build Signature | ||
const sig = new Transaction.Signature() | ||
sig.setAddress(addressBuffer(sansPrefix(acct.addr))) | ||
sig.setKeyId(acct.keyId) | ||
sig.setSignature(hexBuffer(acct.signature)) | ||
// Apply Signature | ||
tx.addEnvelopeSignatures(sig) | ||
} | ||
const req = new SendTransactionRequest() | ||
@@ -59,3 +84,9 @@ req.setTransaction(tx) | ||
if (typeof window !== "undefined") { | ||
window.dispatchEvent( | ||
new CustomEvent("FLOW::TX", {details: {txId: ret.transactionId}}) | ||
) | ||
} | ||
return ret | ||
} |
@@ -10,3 +10,3 @@ import { | ||
isGetBlockByHeight, | ||
isPing | ||
isPing, | ||
} from "@onflow/interaction" | ||
@@ -25,3 +25,3 @@ import {sendTransaction} from "./send-transaction" | ||
export const send = async (ix, opts = {}) => { | ||
opts.node = opts.node || await config().get("accessNode.api") | ||
opts.node = opts.node || (await config().get("accessNode.api")) | ||
ix = await ix | ||
@@ -28,0 +28,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
162863
530
7
+ Added@onflow/util-address@^0.0.0
+ Added@onflow/util-address@0.0.0(transitive)