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

@onflow/send

Package Overview
Dependencies
Maintainers
7
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.5 to 0.0.6

7

CHANGELOG.md

@@ -5,5 +5,10 @@ ### Unreleased

### 0.0.6 -- 2020-04-20
- 2020-04-20 -- Removed `@onflow/bytes`
- 2020-04-19 **BREAKING** -- Updates `sendGetTransaction` to `sendGetTransactionStatus`. Updates internal functionality of `sendTransaction` and `sendGetEvents` according to the latest AccessAPI spec.
### 0.0.5 -- 2020-04-18
- 2020-04-18 **BREAKING** -- Updated `send-transaction.js` to use `transactionId` instead of `transactionHash`
- 2020-04-18 **BREAKING** -- Updated `send-transaction.js` response to use `transactionId` instead of `transactionHash`
- 2020-04-18 -- VSN response 0.0.1 -> 0.0.2 breaking

@@ -10,0 +15,0 @@ - Removed `decodeInstructions`

2

dist/send.js

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

var e=require("@onflow/interaction"),t=require("@onflow/protobuf"),r=require("@onflow/response"),n=require("@onflow/bytes"),s=require("@improbable-eng/grpc-web"),a=require("@improbable-eng/grpc-web-node-http-transport"),o=function(e,t,r){try{return Promise.resolve(new Promise(function(n,a){s.grpc.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===s.grpc.Code.OK?n(e.message):a(new Error(t))}})}))}catch(e){return Promise.reject(e)}};s.grpc.setDefaultTransport(a.NodeHttpTransport()),exports.send=function(s,a){void 0===a&&(a={});try{switch(!0){case e.isTransaction(s):return Promise.resolve(function(e,s){void 0===s&&(s={});try{var a=e.authz.map(function(e){var r=new t.AccountSignature;return r.setAccount(n.addressToBuffer(n.bytes(e.acct,20))),r.setSignature(e.signature),r}),c=new t.AccountSignature;c.setAccount(n.addressToBuffer(n.bytes(e.payer.acct,20))),c.setSignature(e.payer.signature);var i=c,u=new t.Transaction;u.setScript(n.scriptToBuffer(e.payload.code)),u.setNonce(e.payload.nonce),u.setComputeLimit(e.payload.limit),u.setReferenceBlockHash(e.payload.ref?n.hashToBuffer(e.payload.ref):null),u.setPayeraccount(n.addressToBuffer(n.bytes(e.payer.acct,20))),e.authz.forEach(function(e){return u.addScriptaccounts(n.addressToBuffer(n.bytes(e.acct,20)))}),a.forEach(function(e){return u.addSignatures(e)}),a.push(i);var g=new t.SendTransactionRequest;return g.setTransaction(u),Promise.resolve(o(s.node,t.ObserveService.SendTransaction,g)).then(function(t){var s=r.response();return s.tag=e.tag,s.transactionId=n.bufferToHexString(t.getHash_asU8()),s})}catch(e){return Promise.reject(e)}}(s,a));case e.isGetTransactionStatus(s):return Promise.resolve(function(e,s){void 0===s&&(s={});try{var a=new t.GetTransactionResultRequest;return a.setHash(n.hashToBuffer(e.txId)),Promise.resolve(o(s.node,t.AccessAPI.GetTransactionResult,a)).then(function(t){var s=t.getEventsList(),a=r.response();return a.tag=e.tag,a.transaction={status:t.getStatus(),statusCode:t.getStatusCode(),errorMessage:t.getErrorMessage(),events:s.map(function(e){return{type:e.getType(),transactionId:n.bufferToHexString(e.getTransactionId_asU8()),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:e.getPayload_asU8()}})},a})}catch(e){return Promise.reject(e)}}(s,a));case e.isScript(s):return Promise.resolve(function(e,s){void 0===s&&(s={});try{var a=new t.ExecuteScriptAtLatestBlockRequest,c=n.scriptToBuffer(e.payload.code);return a.setScript(c),Promise.resolve(o(s.node,t.AccessAPI.ExecuteScriptAtLatestBlock,a)).then(function(t){var n=r.response();return n.tag=e.tag,n.encodedData=t.getValue_asU8(),n})}catch(e){return Promise.reject(e)}}(s,a));case e.isGetAccount(s):return Promise.resolve(function(e,s){void 0===s&&(s={});try{var a=new t.GetAccountRequest,c=n.addressToBuffer(n.bytes(e.acct,20));return a.setAddress(c),Promise.resolve(o(s.node,t.AccessAPI.GetAccount,a)).then(function(t){var s=r.response();s.tag=e.tag;var a=t.getAccount();return s.account={address:n.bufferToHexString(a.getAddress_asU8()),balance:a.getBalance(),code:a.getCode_asU8(),keys:a.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:n.bufferToHexString(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},s})}catch(e){return Promise.reject(e)}}(s,a));case e.isGetEvents(s):return Promise.resolve(function(e,s){void 0===s&&(s={});try{var a=new t.GetEventsForHeightRange;return a.setType(e.eventType),a.setStartHeight(Number(e.bounds.start)),a.setEndHeight(Number(e.bounds.end)),Promise.resolve(o(s.node,t.AccessAPI.GetEvents,a)).then(function(t){var s=r.response();s.tag=e.tag;var a=t.getEventsList();return s.events=a.map(function(e){return{type:e.getType(),transactionHash:n.bufferToHexString(e.getTransactionHash_asU8()),index:e.getIndex(),payload:e.getPayload_asU8()}}),s})}catch(e){return Promise.reject(e)}}(s,a));case e.isGetLatestBlock(s):return Promise.resolve(function(e,s){void 0===s&&(s={});try{var a=new t.GetLatestBlockRequest;return a.setIsSealed(e.isSealed),Promise.resolve(o(s.node,t.AccessAPI.GetLatestBlock,a)).then(function(t){var s=t.getBlock(),a=s.getCollectionGuaranteesList(),o=s.getBlockSealsList(),c=s.getSignaturesList(),i=r.response();return i.tag=e.tag,i.latestBlock={id:n.bufferToHexString(s.getId_asU8()),parentId:n.bufferToHexString(s.getParentId_asU8()),height:s.getHeight(),timestamp:s.getTimestamp(),collectionGuarantees:a.map(function(e){return{collectionId:n.bufferToHexString(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:n.bufferToHexString(e.getBlockId_asU8()),executionReceiptId:n.bufferToHexString(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:c},i})}catch(e){return Promise.reject(e)}}(s,a));case e.isPing(s):return Promise.resolve(function(e,n){void 0===n&&(n={});try{var s=new t.PingRequest;return Promise.resolve(o(n.node,t.AccessAPI.Ping,s)).then(function(t){var n=r.response();return n.tag=e.tag,n})}catch(e){return Promise.reject(e)}}(s,a));default:return Promise.resolve(s)}}catch(e){return Promise.reject(e)}};
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"),a=function(e,t,r){try{return Promise.resolve(new Promise(function(s,a){n.grpc.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===n.grpc.Code.OK?s(e.message):a(new Error(t))}})}))}catch(e){return Promise.reject(e)}};n.grpc.setDefaultTransport(s.NodeHttpTransport());var o=function(e){return Buffer.from(e,"hex")},i=function(e){return Buffer.from(e.padStart(40,0),"hex")},c=function(e){return Buffer.from(e).toString("hex")},u=function(e){return Buffer.from(e).toString("hex")};exports.send=function(n,s){void 0===s&&(s={});try{switch(!0){case e.isTransaction(n):return Promise.resolve(function(e,n){void 0===n&&(n={});try{var s=new t.Transaction;s.setScript(Buffer.from(e.payload.code,"utf8")),s.setGasLimit(e.payload.limit),s.setReferenceBlockId(e.payload.ref?o(e.payload.ref):null),s.setPayer(i(e.payer.acct)),e.authz.forEach(function(e){return s.addAuthorizers(i(e.acct))});var c=new t.Transaction.ProposalKey;c.setAddress(i(e.proposer.addr)),c.setKeyId(e.proposer.keyId),c.setSequenceNumber(e.proposer.sequenceNum),s.setProposalKey(c),e.authz.forEach(function(e){if(null!==e.signature){var r=new t.Transaction.Signature;r.setAddress(i(e.acct)),r.setKeyId(e.keyId),r.setSignature(o(e.signature)),s.addPayloadSignatures(r)}});var u=new t.Transaction.Signature;u.setAddress(i(e.payer.acct)),u.setKeyId(e.payer.keyId),u.setSignature(o(e.payer.signature)),s.addEnvelopeSignatures(u);var g=new t.SendTransactionRequest;return g.setTransaction(s),Promise.resolve(a(n.node,t.AccessAPI.SendTransaction,g)).then(function(t){var n,s=r.response();return s.tag=e.tag,s.transactionHash=(n=t.getId_asU8(),Buffer.from(n).toString("hex")),s})}catch(e){return Promise.reject(e)}}(n,s));case e.isGetTransactionStatus(n):return Promise.resolve(function(e,n){void 0===n&&(n={});try{var s=new t.GetTransactionRequest;return s.setId(hashBuffer(e.txId)),Promise.resolve(a(n.node,t.AccessAPI.GetTransactionResult,s)).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:e.getPayload_asU8()};var t})},s})}catch(e){return Promise.reject(e)}}(n,s));case e.isScript(n):return Promise.resolve(function(e,n){void 0===n&&(n={});try{var s=new t.ExecuteScriptAtLatestBlockRequest,o=Buffer.from(e.payload.code,"utf8");return s.setScript(o),Promise.resolve(a(n.node,t.AccessAPI.ExecuteScriptAtLatestBlock,s)).then(function(t){var n=r.response();return n.tag=e.tag,n.encodedData=t.getValue_asU8(),n})}catch(e){return Promise.reject(e)}}(n,s));case e.isGetAccount(n):return Promise.resolve(function(e,n){void 0===n&&(n={});try{var s=new t.GetAccountRequest;return s.setAddress(Buffer.from(e.acct.padStart(40,0),"hex")),Promise.resolve(a(n.node,t.AccessAPI.GetAccount,s)).then(function(t){var n=r.response();n.tag=e.tag;var s=t.getAccount();return n.account={address:c(s.getAddress_asU8()),balance:s.getBalance(),code:s.getCode_asU8(),keys:s.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:c(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 Promise.resolve(function(e,n){void 0===n&&(n={});try{var s=new t.GetEventsForHeightRangeRequest;return s.setType(e.eventType),s.setStartHeight(Number(e.bounds.start)),s.setEndHeight(Number(e.bounds.end)),Promise.resolve(a(n.node,t.AccessAPI.GetEventsForHeightRange,s)).then(function(t){var n=r.response();n.tag=e.tag;var s=t.getResultsList();return n.events=s.map(function(e){var t=e.getEventsList();return{blockId:e.getBlockId(),blockHeight:e.getBlockHeight(),events:t.map(function(e){return{type:e.getType(),transactionId:(t=e.getTransactionId_asU8(),Buffer.from(t).toString("hex")),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:e.getPayload_asU8()};var t})}}),n})}catch(e){return Promise.reject(e)}}(n,s));case e.isGetLatestBlock(n):return Promise.resolve(function(e,n){void 0===n&&(n={});try{var s=new t.GetLatestBlockRequest;return s.setIsSealed(e.isSealed),Promise.resolve(a(n.node,t.AccessAPI.GetLatestBlock,s)).then(function(t){var n=t.getBlock(),s=n.getCollectionGuaranteesList(),a=n.getBlockSealsList(),o=n.getSignaturesList(),i=r.response();return i.tag=e.tag,i.latestBlock={id:u(n.getId_asU8()),parentId:u(n.getParentId_asU8()),height:n.getHeight(),timestamp:n.getTimestamp(),collectionGuarantees:s.map(function(e){return{collectionId:u(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:a.map(function(e){return{blockId:u(e.getBlockId_asU8()),executionReceiptId:u(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:o},i})}catch(e){return Promise.reject(e)}}(n,s));case e.isPing(n):return Promise.resolve(function(e,n){void 0===n&&(n={});try{var s=new t.PingRequest;return Promise.resolve(a(n.node,t.AccessAPI.Ping,s)).then(function(t){var n=r.response();return n.tag=e.tag,n})}catch(e){return Promise.reject(e)}}(n,s));default:return Promise.resolve(n)}}catch(e){return Promise.reject(e)}};
//# sourceMappingURL=send.js.map

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

import{isPing as e,isGetLatestBlock as t,isGetEvents as r,isGetAccount as n,isScript as a,isGetTransactionStatus as o,isTransaction as s}from"@onflow/interaction";import{AccountSignature as c,Transaction as i,SendTransactionRequest as u,ObserveService as g,GetTransactionResultRequest as d,AccessAPI as l,ExecuteScriptAtLatestBlockRequest as m,GetAccountRequest as p,GetEventsForHeightRange as v,GetLatestBlockRequest as f,PingRequest as h}from"@onflow/protobuf";import{response as y}from"@onflow/response";import{addressToBuffer as P,bytes as S,scriptToBuffer as w,hashToBuffer as I,bufferToHexString as b}from"@onflow/bytes";import{grpc as x}from"@improbable-eng/grpc-web";import{NodeHttpTransport as U}from"@improbable-eng/grpc-web-node-http-transport";var _=function(e,t,r){try{return Promise.resolve(new Promise(function(n,a){x.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===x.Code.OK?n(e.message):a(new Error(t))}})}))}catch(e){return Promise.reject(e)}};x.setDefaultTransport(U());var A=function(x,U){void 0===U&&(U={});try{switch(!0){case s(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=e.authz.map(function(e){var t=new c;return t.setAccount(P(S(e.acct,20))),t.setSignature(e.signature),t}),n=new c;n.setAccount(P(S(e.payer.acct,20))),n.setSignature(e.payer.signature);var a=n,o=new i;o.setScript(w(e.payload.code)),o.setNonce(e.payload.nonce),o.setComputeLimit(e.payload.limit),o.setReferenceBlockHash(e.payload.ref?I(e.payload.ref):null),o.setPayeraccount(P(S(e.payer.acct,20))),e.authz.forEach(function(e){return o.addScriptaccounts(P(S(e.acct,20)))}),r.forEach(function(e){return o.addSignatures(e)}),r.push(a);var s=new u;return s.setTransaction(o),Promise.resolve(_(t.node,g.SendTransaction,s)).then(function(t){var r=y();return r.tag=e.tag,r.transactionId=b(t.getHash_asU8()),r})}catch(e){return Promise.reject(e)}}(x,U));case o(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new d;return r.setHash(I(e.txId)),Promise.resolve(_(t.node,l.GetTransactionResult,r)).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:b(e.getTransactionId_asU8()),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:e.getPayload_asU8()}})},n})}catch(e){return Promise.reject(e)}}(x,U));case a(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new m,n=w(e.payload.code);return r.setScript(n),Promise.resolve(_(t.node,l.ExecuteScriptAtLatestBlock,r)).then(function(t){var r=y();return r.tag=e.tag,r.encodedData=t.getValue_asU8(),r})}catch(e){return Promise.reject(e)}}(x,U));case n(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new p,n=P(S(e.acct,20));return r.setAddress(n),Promise.resolve(_(t.node,l.GetAccount,r)).then(function(t){var r=y();r.tag=e.tag;var n=t.getAccount();return r.account={address:b(n.getAddress_asU8()),balance:n.getBalance(),code:n.getCode_asU8(),keys:n.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:b(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},r})}catch(e){return Promise.reject(e)}}(x,U));case r(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new v;return r.setType(e.eventType),r.setStartHeight(Number(e.bounds.start)),r.setEndHeight(Number(e.bounds.end)),Promise.resolve(_(t.node,l.GetEvents,r)).then(function(t){var r=y();r.tag=e.tag;var n=t.getEventsList();return r.events=n.map(function(e){return{type:e.getType(),transactionHash:b(e.getTransactionHash_asU8()),index:e.getIndex(),payload:e.getPayload_asU8()}}),r})}catch(e){return Promise.reject(e)}}(x,U));case t(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new f;return r.setIsSealed(e.isSealed),Promise.resolve(_(t.node,l.GetLatestBlock,r)).then(function(t){var r=t.getBlock(),n=r.getCollectionGuaranteesList(),a=r.getBlockSealsList(),o=r.getSignaturesList(),s=y();return s.tag=e.tag,s.latestBlock={id:b(r.getId_asU8()),parentId:b(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:b(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:a.map(function(e){return{blockId:b(e.getBlockId_asU8()),executionReceiptId:b(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:o},s})}catch(e){return Promise.reject(e)}}(x,U));case e(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new h;return Promise.resolve(_(t.node,l.Ping,r)).then(function(t){var r=y();return r.tag=e.tag,r})}catch(e){return Promise.reject(e)}}(x,U));default:return Promise.resolve(x)}}catch(e){return Promise.reject(e)}};export{A as send};
import{isPing as e,isGetLatestBlock as t,isGetEvents as r,isGetAccount as n,isScript as a,isGetTransactionStatus as o,isTransaction as s}from"@onflow/interaction";import{Transaction as i,SendTransactionRequest as u,AccessAPI as c,GetTransactionRequest as g,ExecuteScriptAtLatestBlockRequest as d,GetAccountRequest as l,GetEventsForHeightRangeRequest as f,GetLatestBlockRequest as m,PingRequest as p}from"@onflow/protobuf";import{response as v}from"@onflow/response";import{grpc as h}from"@improbable-eng/grpc-web";import{NodeHttpTransport as y}from"@improbable-eng/grpc-web-node-http-transport";var I=function(e,t,r){try{return Promise.resolve(new Promise(function(n,a){h.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===h.Code.OK?n(e.message):a(new Error(t))}})}))}catch(e){return Promise.reject(e)}};h.setDefaultTransport(y());var P=function(e){return Buffer.from(e,"hex")},S=function(e){return Buffer.from(e.padStart(40,0),"hex")},x=function(e){return Buffer.from(e).toString("hex")},b=function(e){return Buffer.from(e).toString("hex")},B=function(h,y){void 0===y&&(y={});try{switch(!0){case s(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new i;r.setScript(Buffer.from(e.payload.code,"utf8")),r.setGasLimit(e.payload.limit),r.setReferenceBlockId(e.payload.ref?P(e.payload.ref):null),r.setPayer(S(e.payer.acct)),e.authz.forEach(function(e){return r.addAuthorizers(S(e.acct))});var n=new i.ProposalKey;n.setAddress(S(e.proposer.addr)),n.setKeyId(e.proposer.keyId),n.setSequenceNumber(e.proposer.sequenceNum),r.setProposalKey(n),e.authz.forEach(function(e){if(null!==e.signature){var t=new i.Signature;t.setAddress(S(e.acct)),t.setKeyId(e.keyId),t.setSignature(P(e.signature)),r.addPayloadSignatures(t)}});var a=new i.Signature;a.setAddress(S(e.payer.acct)),a.setKeyId(e.payer.keyId),a.setSignature(P(e.payer.signature)),r.addEnvelopeSignatures(a);var o=new u;return o.setTransaction(r),Promise.resolve(I(t.node,c.SendTransaction,o)).then(function(t){var r,n=v();return n.tag=e.tag,n.transactionHash=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),n})}catch(e){return Promise.reject(e)}}(h,y));case o(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new g;return r.setId(hashBuffer(e.txId)),Promise.resolve(I(t.node,c.GetTransactionResult,r)).then(function(t){var r=t.getEventsList(),n=v();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:e.getPayload_asU8()};var t})},n})}catch(e){return Promise.reject(e)}}(h,y));case a(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new d,n=Buffer.from(e.payload.code,"utf8");return r.setScript(n),Promise.resolve(I(t.node,c.ExecuteScriptAtLatestBlock,r)).then(function(t){var r=v();return r.tag=e.tag,r.encodedData=t.getValue_asU8(),r})}catch(e){return Promise.reject(e)}}(h,y));case n(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new l;return r.setAddress(Buffer.from(e.acct.padStart(40,0),"hex")),Promise.resolve(I(t.node,c.GetAccount,r)).then(function(t){var r=v();r.tag=e.tag;var n=t.getAccount();return r.account={address:x(n.getAddress_asU8()),balance:n.getBalance(),code:n.getCode_asU8(),keys:n.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:x(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},r})}catch(e){return Promise.reject(e)}}(h,y));case r(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new f;return r.setType(e.eventType),r.setStartHeight(Number(e.bounds.start)),r.setEndHeight(Number(e.bounds.end)),Promise.resolve(I(t.node,c.GetEventsForHeightRange,r)).then(function(t){var r=v();r.tag=e.tag;var n=t.getResultsList();return r.events=n.map(function(e){var t=e.getEventsList();return{blockId:e.getBlockId(),blockHeight:e.getBlockHeight(),events:t.map(function(e){return{type:e.getType(),transactionId:(t=e.getTransactionId_asU8(),Buffer.from(t).toString("hex")),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:e.getPayload_asU8()};var t})}}),r})}catch(e){return Promise.reject(e)}}(h,y));case t(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new m;return r.setIsSealed(e.isSealed),Promise.resolve(I(t.node,c.GetLatestBlock,r)).then(function(t){var r=t.getBlock(),n=r.getCollectionGuaranteesList(),a=r.getBlockSealsList(),o=r.getSignaturesList(),s=v();return s.tag=e.tag,s.latestBlock={id:b(r.getId_asU8()),parentId:b(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:b(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:a.map(function(e){return{blockId:b(e.getBlockId_asU8()),executionReceiptId:b(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:o},s})}catch(e){return Promise.reject(e)}}(h,y));case e(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new p;return Promise.resolve(I(t.node,c.Ping,r)).then(function(t){var r=v();return r.tag=e.tag,r})}catch(e){return Promise.reject(e)}}(h,y));default:return Promise.resolve(h)}}catch(e){return Promise.reject(e)}};export{B as send};
//# sourceMappingURL=send.modern.js.map

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

import{isPing as e,isGetLatestBlock as t,isGetEvents as r,isGetAccount as n,isScript as a,isGetTransactionStatus as o,isTransaction as s}from"@onflow/interaction";import{AccountSignature as c,Transaction as i,SendTransactionRequest as u,ObserveService as g,GetTransactionResultRequest as d,AccessAPI as l,ExecuteScriptAtLatestBlockRequest as m,GetAccountRequest as p,GetEventsForHeightRange as v,GetLatestBlockRequest as f,PingRequest as h}from"@onflow/protobuf";import{response as y}from"@onflow/response";import{addressToBuffer as P,bytes as S,scriptToBuffer as w,hashToBuffer as I,bufferToHexString as b}from"@onflow/bytes";import{grpc as x}from"@improbable-eng/grpc-web";import{NodeHttpTransport as U}from"@improbable-eng/grpc-web-node-http-transport";var _=function(e,t,r){try{return Promise.resolve(new Promise(function(n,a){x.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===x.Code.OK?n(e.message):a(new Error(t))}})}))}catch(e){return Promise.reject(e)}};x.setDefaultTransport(U());var A=function(x,U){void 0===U&&(U={});try{switch(!0){case s(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=e.authz.map(function(e){var t=new c;return t.setAccount(P(S(e.acct,20))),t.setSignature(e.signature),t}),n=new c;n.setAccount(P(S(e.payer.acct,20))),n.setSignature(e.payer.signature);var a=n,o=new i;o.setScript(w(e.payload.code)),o.setNonce(e.payload.nonce),o.setComputeLimit(e.payload.limit),o.setReferenceBlockHash(e.payload.ref?I(e.payload.ref):null),o.setPayeraccount(P(S(e.payer.acct,20))),e.authz.forEach(function(e){return o.addScriptaccounts(P(S(e.acct,20)))}),r.forEach(function(e){return o.addSignatures(e)}),r.push(a);var s=new u;return s.setTransaction(o),Promise.resolve(_(t.node,g.SendTransaction,s)).then(function(t){var r=y();return r.tag=e.tag,r.transactionId=b(t.getHash_asU8()),r})}catch(e){return Promise.reject(e)}}(x,U));case o(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new d;return r.setHash(I(e.txId)),Promise.resolve(_(t.node,l.GetTransactionResult,r)).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:b(e.getTransactionId_asU8()),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:e.getPayload_asU8()}})},n})}catch(e){return Promise.reject(e)}}(x,U));case a(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new m,n=w(e.payload.code);return r.setScript(n),Promise.resolve(_(t.node,l.ExecuteScriptAtLatestBlock,r)).then(function(t){var r=y();return r.tag=e.tag,r.encodedData=t.getValue_asU8(),r})}catch(e){return Promise.reject(e)}}(x,U));case n(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new p,n=P(S(e.acct,20));return r.setAddress(n),Promise.resolve(_(t.node,l.GetAccount,r)).then(function(t){var r=y();r.tag=e.tag;var n=t.getAccount();return r.account={address:b(n.getAddress_asU8()),balance:n.getBalance(),code:n.getCode_asU8(),keys:n.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:b(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},r})}catch(e){return Promise.reject(e)}}(x,U));case r(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new v;return r.setType(e.eventType),r.setStartHeight(Number(e.bounds.start)),r.setEndHeight(Number(e.bounds.end)),Promise.resolve(_(t.node,l.GetEvents,r)).then(function(t){var r=y();r.tag=e.tag;var n=t.getEventsList();return r.events=n.map(function(e){return{type:e.getType(),transactionHash:b(e.getTransactionHash_asU8()),index:e.getIndex(),payload:e.getPayload_asU8()}}),r})}catch(e){return Promise.reject(e)}}(x,U));case t(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new f;return r.setIsSealed(e.isSealed),Promise.resolve(_(t.node,l.GetLatestBlock,r)).then(function(t){var r=t.getBlock(),n=r.getCollectionGuaranteesList(),a=r.getBlockSealsList(),o=r.getSignaturesList(),s=y();return s.tag=e.tag,s.latestBlock={id:b(r.getId_asU8()),parentId:b(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:b(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:a.map(function(e){return{blockId:b(e.getBlockId_asU8()),executionReceiptId:b(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:o},s})}catch(e){return Promise.reject(e)}}(x,U));case e(x):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new h;return Promise.resolve(_(t.node,l.Ping,r)).then(function(t){var r=y();return r.tag=e.tag,r})}catch(e){return Promise.reject(e)}}(x,U));default:return Promise.resolve(x)}}catch(e){return Promise.reject(e)}};export{A as send};
import{isPing as e,isGetLatestBlock as t,isGetEvents as r,isGetAccount as n,isScript as a,isGetTransactionStatus as o,isTransaction as s}from"@onflow/interaction";import{Transaction as i,SendTransactionRequest as u,AccessAPI as c,GetTransactionRequest as g,ExecuteScriptAtLatestBlockRequest as d,GetAccountRequest as l,GetEventsForHeightRangeRequest as f,GetLatestBlockRequest as m,PingRequest as p}from"@onflow/protobuf";import{response as v}from"@onflow/response";import{grpc as h}from"@improbable-eng/grpc-web";import{NodeHttpTransport as y}from"@improbable-eng/grpc-web-node-http-transport";var I=function(e,t,r){try{return Promise.resolve(new Promise(function(n,a){h.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===h.Code.OK?n(e.message):a(new Error(t))}})}))}catch(e){return Promise.reject(e)}};h.setDefaultTransport(y());var P=function(e){return Buffer.from(e,"hex")},S=function(e){return Buffer.from(e.padStart(40,0),"hex")},x=function(e){return Buffer.from(e).toString("hex")},b=function(e){return Buffer.from(e).toString("hex")},B=function(h,y){void 0===y&&(y={});try{switch(!0){case s(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new i;r.setScript(Buffer.from(e.payload.code,"utf8")),r.setGasLimit(e.payload.limit),r.setReferenceBlockId(e.payload.ref?P(e.payload.ref):null),r.setPayer(S(e.payer.acct)),e.authz.forEach(function(e){return r.addAuthorizers(S(e.acct))});var n=new i.ProposalKey;n.setAddress(S(e.proposer.addr)),n.setKeyId(e.proposer.keyId),n.setSequenceNumber(e.proposer.sequenceNum),r.setProposalKey(n),e.authz.forEach(function(e){if(null!==e.signature){var t=new i.Signature;t.setAddress(S(e.acct)),t.setKeyId(e.keyId),t.setSignature(P(e.signature)),r.addPayloadSignatures(t)}});var a=new i.Signature;a.setAddress(S(e.payer.acct)),a.setKeyId(e.payer.keyId),a.setSignature(P(e.payer.signature)),r.addEnvelopeSignatures(a);var o=new u;return o.setTransaction(r),Promise.resolve(I(t.node,c.SendTransaction,o)).then(function(t){var r,n=v();return n.tag=e.tag,n.transactionHash=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),n})}catch(e){return Promise.reject(e)}}(h,y));case o(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new g;return r.setId(hashBuffer(e.txId)),Promise.resolve(I(t.node,c.GetTransactionResult,r)).then(function(t){var r=t.getEventsList(),n=v();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:e.getPayload_asU8()};var t})},n})}catch(e){return Promise.reject(e)}}(h,y));case a(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new d,n=Buffer.from(e.payload.code,"utf8");return r.setScript(n),Promise.resolve(I(t.node,c.ExecuteScriptAtLatestBlock,r)).then(function(t){var r=v();return r.tag=e.tag,r.encodedData=t.getValue_asU8(),r})}catch(e){return Promise.reject(e)}}(h,y));case n(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new l;return r.setAddress(Buffer.from(e.acct.padStart(40,0),"hex")),Promise.resolve(I(t.node,c.GetAccount,r)).then(function(t){var r=v();r.tag=e.tag;var n=t.getAccount();return r.account={address:x(n.getAddress_asU8()),balance:n.getBalance(),code:n.getCode_asU8(),keys:n.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:x(e.getPublicKey_asU8()),signAlgo:e.getSignAlgo(),hashAlgo:e.getHashAlgo(),weight:e.getWeight(),sequenceNumber:e.getSequenceNumber()}})},r})}catch(e){return Promise.reject(e)}}(h,y));case r(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new f;return r.setType(e.eventType),r.setStartHeight(Number(e.bounds.start)),r.setEndHeight(Number(e.bounds.end)),Promise.resolve(I(t.node,c.GetEventsForHeightRange,r)).then(function(t){var r=v();r.tag=e.tag;var n=t.getResultsList();return r.events=n.map(function(e){var t=e.getEventsList();return{blockId:e.getBlockId(),blockHeight:e.getBlockHeight(),events:t.map(function(e){return{type:e.getType(),transactionId:(t=e.getTransactionId_asU8(),Buffer.from(t).toString("hex")),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:e.getPayload_asU8()};var t})}}),r})}catch(e){return Promise.reject(e)}}(h,y));case t(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new m;return r.setIsSealed(e.isSealed),Promise.resolve(I(t.node,c.GetLatestBlock,r)).then(function(t){var r=t.getBlock(),n=r.getCollectionGuaranteesList(),a=r.getBlockSealsList(),o=r.getSignaturesList(),s=v();return s.tag=e.tag,s.latestBlock={id:b(r.getId_asU8()),parentId:b(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:b(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:a.map(function(e){return{blockId:b(e.getBlockId_asU8()),executionReceiptId:b(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:o},s})}catch(e){return Promise.reject(e)}}(h,y));case e(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new p;return Promise.resolve(I(t.node,c.Ping,r)).then(function(t){var r=v();return r.tag=e.tag,r})}catch(e){return Promise.reject(e)}}(h,y));default:return Promise.resolve(h)}}catch(e){return Promise.reject(e)}};export{B 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/bytes"),require("@improbable-eng/grpc-web"),require("@improbable-eng/grpc-web-node-http-transport")):"function"==typeof define&&define.amd?define(["exports","@onflow/interaction","@onflow/protobuf","@onflow/response","@onflow/bytes","@improbable-eng/grpc-web","@improbable-eng/grpc-web-node-http-transport"],t):t((e=e||self).send={},e.interaction,e.protobuf,e.response,e.bytes,e.grpcWeb,e.grpcWebNodeHttpTransport)}(this,function(e,t,r,n,s,o,a){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()),e.send=function(e,o){void 0===o&&(o={});try{switch(!0){case t.isTransaction(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var o=e.authz.map(function(e){var t=new r.AccountSignature;return t.setAccount(s.addressToBuffer(s.bytes(e.acct,20))),t.setSignature(e.signature),t}),a=new r.AccountSignature;a.setAccount(s.addressToBuffer(s.bytes(e.payer.acct,20))),a.setSignature(e.payer.signature);var i=a,u=new r.Transaction;u.setScript(s.scriptToBuffer(e.payload.code)),u.setNonce(e.payload.nonce),u.setComputeLimit(e.payload.limit),u.setReferenceBlockHash(e.payload.ref?s.hashToBuffer(e.payload.ref):null),u.setPayeraccount(s.addressToBuffer(s.bytes(e.payer.acct,20))),e.authz.forEach(function(e){return u.addScriptaccounts(s.addressToBuffer(s.bytes(e.acct,20)))}),o.forEach(function(e){return u.addSignatures(e)}),o.push(i);var g=new r.SendTransactionRequest;return g.setTransaction(u),Promise.resolve(c(t.node,r.ObserveService.SendTransaction,g)).then(function(t){var r=n.response();return r.tag=e.tag,r.transactionId=s.bufferToHexString(t.getHash_asU8()),r})}catch(e){return Promise.reject(e)}}(e,o));case t.isGetTransactionStatus(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var o=new r.GetTransactionResultRequest;return o.setHash(s.hashToBuffer(e.txId)),Promise.resolve(c(t.node,r.AccessAPI.GetTransactionResult,o)).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:s.bufferToHexString(e.getTransactionId_asU8()),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:e.getPayload_asU8()}})},o})}catch(e){return Promise.reject(e)}}(e,o));case t.isScript(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var o=new r.ExecuteScriptAtLatestBlockRequest,a=s.scriptToBuffer(e.payload.code);return 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=t.getValue_asU8(),r})}catch(e){return Promise.reject(e)}}(e,o));case t.isGetAccount(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var o=new r.GetAccountRequest,a=s.addressToBuffer(s.bytes(e.acct,20));return o.setAddress(a),Promise.resolve(c(t.node,r.AccessAPI.GetAccount,o)).then(function(t){var r=n.response();r.tag=e.tag;var o=t.getAccount();return r.account={address:s.bufferToHexString(o.getAddress_asU8()),balance:o.getBalance(),code:o.getCode_asU8(),keys:o.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:s.bufferToHexString(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 Promise.resolve(function(e,t){void 0===t&&(t={});try{var o=new r.GetEventsForHeightRange;return o.setType(e.eventType),o.setStartHeight(Number(e.bounds.start)),o.setEndHeight(Number(e.bounds.end)),Promise.resolve(c(t.node,r.AccessAPI.GetEvents,o)).then(function(t){var r=n.response();r.tag=e.tag;var o=t.getEventsList();return r.events=o.map(function(e){return{type:e.getType(),transactionHash:s.bufferToHexString(e.getTransactionHash_asU8()),index:e.getIndex(),payload:e.getPayload_asU8()}}),r})}catch(e){return Promise.reject(e)}}(e,o));case t.isGetLatestBlock(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var o=new r.GetLatestBlockRequest;return o.setIsSealed(e.isSealed),Promise.resolve(c(t.node,r.AccessAPI.GetLatestBlock,o)).then(function(t){var r=t.getBlock(),o=r.getCollectionGuaranteesList(),a=r.getBlockSealsList(),c=r.getSignaturesList(),i=n.response();return i.tag=e.tag,i.latestBlock={id:s.bufferToHexString(r.getId_asU8()),parentId:s.bufferToHexString(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:o.map(function(e){return{collectionId:s.bufferToHexString(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:a.map(function(e){return{blockId:s.bufferToHexString(e.getBlockId_asU8()),executionReceiptId:s.bufferToHexString(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:c},i})}catch(e){return Promise.reject(e)}}(e,o));case t.isPing(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{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,o));default:return Promise.resolve(e)}}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("@improbable-eng/grpc-web"),require("@improbable-eng/grpc-web-node-http-transport")):"function"==typeof define&&define.amd?define(["exports","@onflow/interaction","@onflow/protobuf","@onflow/response","@improbable-eng/grpc-web","@improbable-eng/grpc-web-node-http-transport"],t):t((e=e||self).send={},e.interaction,e.protobuf,e.response,e.grpcWeb,e.grpcWebNodeHttpTransport)}(this,function(e,t,r,n,s,o){var a=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 i=function(e){return Buffer.from(e,"hex")},c=function(e){return Buffer.from(e.padStart(40,0),"hex")},u=function(e){return Buffer.from(e).toString("hex")},g=function(e){return Buffer.from(e).toString("hex")};e.send=function(e,s){void 0===s&&(s={});try{switch(!0){case t.isTransaction(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var s=new r.Transaction;s.setScript(Buffer.from(e.payload.code,"utf8")),s.setGasLimit(e.payload.limit),s.setReferenceBlockId(e.payload.ref?i(e.payload.ref):null),s.setPayer(c(e.payer.acct)),e.authz.forEach(function(e){return s.addAuthorizers(c(e.acct))});var o=new r.Transaction.ProposalKey;o.setAddress(c(e.proposer.addr)),o.setKeyId(e.proposer.keyId),o.setSequenceNumber(e.proposer.sequenceNum),s.setProposalKey(o),e.authz.forEach(function(e){if(null!==e.signature){var t=new r.Transaction.Signature;t.setAddress(c(e.acct)),t.setKeyId(e.keyId),t.setSignature(i(e.signature)),s.addPayloadSignatures(t)}});var u=new r.Transaction.Signature;u.setAddress(c(e.payer.acct)),u.setKeyId(e.payer.keyId),u.setSignature(i(e.payer.signature)),s.addEnvelopeSignatures(u);var g=new r.SendTransactionRequest;return g.setTransaction(s),Promise.resolve(a(t.node,r.AccessAPI.SendTransaction,g)).then(function(t){var r,s=n.response();return s.tag=e.tag,s.transactionHash=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),s})}catch(e){return Promise.reject(e)}}(e,s));case t.isGetTransactionStatus(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var s=new r.GetTransactionRequest;return s.setId(hashBuffer(e.txId)),Promise.resolve(a(t.node,r.AccessAPI.GetTransactionResult,s)).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:e.getPayload_asU8()};var t})},s})}catch(e){return Promise.reject(e)}}(e,s));case t.isScript(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var s=new r.ExecuteScriptAtLatestBlockRequest,o=Buffer.from(e.payload.code,"utf8");return s.setScript(o),Promise.resolve(a(t.node,r.AccessAPI.ExecuteScriptAtLatestBlock,s)).then(function(t){var r=n.response();return r.tag=e.tag,r.encodedData=t.getValue_asU8(),r})}catch(e){return Promise.reject(e)}}(e,s));case t.isGetAccount(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var s=new r.GetAccountRequest;return s.setAddress(Buffer.from(e.acct.padStart(40,0),"hex")),Promise.resolve(a(t.node,r.AccessAPI.GetAccount,s)).then(function(t){var r=n.response();r.tag=e.tag;var s=t.getAccount();return r.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()}})},r})}catch(e){return Promise.reject(e)}}(e,s));case t.isGetEvents(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var s=new r.GetEventsForHeightRangeRequest;return s.setType(e.eventType),s.setStartHeight(Number(e.bounds.start)),s.setEndHeight(Number(e.bounds.end)),Promise.resolve(a(t.node,r.AccessAPI.GetEventsForHeightRange,s)).then(function(t){var r=n.response();r.tag=e.tag;var s=t.getResultsList();return r.events=s.map(function(e){var t=e.getEventsList();return{blockId:e.getBlockId(),blockHeight:e.getBlockHeight(),events:t.map(function(e){return{type:e.getType(),transactionId:(t=e.getTransactionId_asU8(),Buffer.from(t).toString("hex")),transactionIndex:e.getTransactionIndex(),eventIndex:e.getEventIndex(),payload:e.getPayload_asU8()};var t})}}),r})}catch(e){return Promise.reject(e)}}(e,s));case t.isGetLatestBlock(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var s=new r.GetLatestBlockRequest;return s.setIsSealed(e.isSealed),Promise.resolve(a(t.node,r.AccessAPI.GetLatestBlock,s)).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.latestBlock={id:g(r.getId_asU8()),parentId:g(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.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)}}(e,s));case t.isPing(e):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var s=new r.PingRequest;return Promise.resolve(a(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 Promise.resolve(e)}}catch(e){return Promise.reject(e)}}});
//# sourceMappingURL=send.umd.js.map
{
"name": "@onflow/send",
"version": "0.0.5",
"version": "0.0.6",
"description": "Flow SDK Send",

@@ -39,3 +39,2 @@ "license": "Apache-2.0",

"@improbable-eng/grpc-web-node-http-transport": "^0.12.0",
"@onflow/bytes": "0.0.2",
"@onflow/interaction": "0.0.3",

@@ -42,0 +41,0 @@ "@onflow/protobuf": "0.1.2",

import {ExecuteScriptAtLatestBlockRequest, AccessAPI} from "@onflow/protobuf"
import {scriptToBuffer} from "@onflow/bytes"
import {response} from "@onflow/response"

@@ -8,3 +7,3 @@ import {unary} from "./unary"

const req = new ExecuteScriptAtLatestBlockRequest()
const code = scriptToBuffer(ix.payload.code)
const code = Buffer.from(ix.payload.code, "utf8")
req.setScript(code)

@@ -11,0 +10,0 @@

import {GetAccountRequest, AccessAPI} from "@onflow/protobuf"
import {response} from "@onflow/response"
import {unary} from "./unary"
import {bufferToHexString, addressToBuffer, bytes} from "@onflow/bytes"
const u8ToHex = u8 => Buffer.from(u8).toString("hex")
const paddedHexBuffer = (hex, pad) =>
Buffer.from(hex.padStart(pad * 2, 0), "hex")
const addressBuffer = addr => paddedHexBuffer(addr, 20)
export async function sendGetAccount(ix, opts = {}) {
const req = new GetAccountRequest()
const address = addressToBuffer(bytes(ix.acct, 20))
req.setAddress(address)
req.setAddress(addressBuffer(ix.acct))

@@ -18,3 +22,3 @@ const res = await unary(opts.node, AccessAPI.GetAccount, req)

ret.account = {
address: bufferToHexString(account.getAddress_asU8()),
address: u8ToHex(account.getAddress_asU8()),
balance: account.getBalance(),

@@ -24,7 +28,7 @@ code: account.getCode_asU8(),

index: publicKey.getIndex(),
publicKey: bufferToHexString(publicKey.getPublicKey_asU8()),
publicKey: u8ToHex(publicKey.getPublicKey_asU8()),
signAlgo: publicKey.getSignAlgo(),
hashAlgo: publicKey.getHashAlgo(),
weight: publicKey.getWeight(),
sequenceNumber: publicKey.getSequenceNumber()
sequenceNumber: publicKey.getSequenceNumber(),
})),

@@ -31,0 +35,0 @@ }

@@ -1,8 +0,9 @@

import {GetEventsForHeightRange, AccessAPI} from "@onflow/protobuf"
import {GetEventsForHeightRangeRequest, AccessAPI} from "@onflow/protobuf"
import {response} from "@onflow/response"
import {bufferToHexString} from "@onflow/bytes"
import {unary} from "./unary"
const u8ToHex = u8 => Buffer.from(u8).toString("hex")
export async function sendGetEvents(ix, opts = {}) {
const req = new GetEventsForHeightRange()
const req = new GetEventsForHeightRangeRequest()
req.setType(ix.eventType)

@@ -12,3 +13,3 @@ req.setStartHeight(Number(ix.bounds.start))

const res = await unary(opts.node, AccessAPI.GetEvents, req)
const res = await unary(opts.node, AccessAPI.GetEventsForHeightRange, req)

@@ -18,11 +19,19 @@ let ret = response()

const events = res.getEventsList()
ret.events = events.map(event => ({
type: event.getType(),
transactionHash: bufferToHexString(event.getTransactionHash_asU8()),
index: event.getIndex(),
payload: event.getPayload_asU8(),
}))
const results = res.getResultsList()
ret.events = results.map(result => {
const events = result.getEventsList()
return {
blockId: result.getBlockId(),
blockHeight: result.getBlockHeight(),
events: events.map(event => ({
type: event.getType(),
transactionId: u8ToHex(event.getTransactionId_asU8()),
transactionIndex: event.getTransactionIndex(),
eventIndex: event.getEventIndex(),
payload: event.getPayload_asU8(),
})),
}
})
return ret
}
import {GetLatestBlockRequest, AccessAPI} from "@onflow/protobuf"
import {response} from "@onflow/response"
import {bufferToHexString} from "@onflow/bytes"
import {unary} from "./unary"
const u8ToHex = u8 => Buffer.from(u8).toString("hex")
export async function sendGetLatestBlock(ix, opts = {}) {

@@ -21,13 +22,13 @@ const req = new GetLatestBlockRequest()

ret.latestBlock = {
id: bufferToHexString(latestBlock.getId_asU8()),
parentId: bufferToHexString(latestBlock.getParentId_asU8()),
id: u8ToHex(latestBlock.getId_asU8()),
parentId: u8ToHex(latestBlock.getParentId_asU8()),
height: latestBlock.getHeight(),
timestamp: latestBlock.getTimestamp(),
collectionGuarantees: collectionGuarantees.map(collectionGuarantee => ({
collectionId: bufferToHexString(collectionGuarantee.getCollectionId_asU8()),
signatures: collectionGuarantee.getSignaturesList()
collectionId: u8ToHex(collectionGuarantee.getCollectionId_asU8()),
signatures: collectionGuarantee.getSignaturesList(),
})),
blockSeals: blockSeals.map(blockSeal => ({
blockId: bufferToHexString(blockSeal.getBlockId_asU8()),
executionReceiptId: bufferToHexString(blockSeal.getExecutionReceiptId_asU8()),
blockId: u8ToHex(blockSeal.getBlockId_asU8()),
executionReceiptId: u8ToHex(blockSeal.getExecutionReceiptId_asU8()),
executionReceiptSignatures: blockSeal.getExecutionReceiptSignaturesList(),

@@ -34,0 +35,0 @@ resultApprovalSignatures: blockSeal.getResultApprovalSignaturesList(),

@@ -1,9 +0,11 @@

import {AccessAPI, GetTransactionResultRequest} from "@onflow/protobuf"
import {AccessAPI, GetTransactionRequest} from "@onflow/protobuf"
import {response} from "@onflow/response"
import {bufferToHexString, hashToBuffer} from "@onflow/bytes"
import {unary} from "./unary"
const u8ToHex = u8 => Buffer.from(u8).toString("hex")
const hexBuffer = hex => Buffer.from(hex, "hex")
export async function sendGetTransactionStatus(ix, opts = {}) {
const req = new GetTransactionResultRequest()
req.setHash(hashToBuffer(ix.txId))
const req = new GetTransactionRequest()
req.setId(hashBuffer(ix.txId))

@@ -22,3 +24,3 @@ const res = await unary(opts.node, AccessAPI.GetTransactionResult, req)

type: event.getType(),
transactionId: bufferToHexString(event.getTransactionId_asU8()),
transactionId: u8ToHex(event.getTransactionId_asU8()),
transactionIndex: event.getTransactionIndex(),

@@ -25,0 +27,0 @@ eventIndex: event.getEventIndex(),

@@ -1,56 +0,54 @@

import {
ObserveService,
AccountSignature,
Transaction as TransactionMessage,
SendTransactionRequest,
} from "@onflow/protobuf"
import {AccessAPI, Transaction, SendTransactionRequest} from "@onflow/protobuf"
import {response} from "@onflow/response"
import {
bufferToHexString,
scriptToBuffer,
hashToBuffer,
addressToBuffer,
bytes,
} from "@onflow/bytes"
import {unary} from "./unary"
const u8ToHex = u8 => Buffer.from(u8).toString("hex")
const paddedHexBuffer = (hex, pad) =>
Buffer.from(hex.padStart(pad * 2, 0), "hex")
const scriptBuffer = script => Buffer.from(script, "utf8")
const hexBuffer = hex => Buffer.from(hex, "hex")
const addressBuffer = addr => paddedHexBuffer(addr, 20)
export async function sendTransaction(ix, opts = {}) {
const accountSignatures = ix.authz.map(sig => {
const accountSig = new AccountSignature()
accountSig.setAccount(addressToBuffer(bytes(sig.acct, 20)))
accountSig.setSignature(sig.signature)
return accountSig
const tx = new Transaction()
tx.setScript(scriptBuffer(ix.payload.code))
tx.setGasLimit(ix.payload.limit)
tx.setReferenceBlockId(ix.payload.ref ? hexBuffer(ix.payload.ref) : null)
tx.setPayer(addressBuffer(ix.payer.acct))
ix.authz.forEach(a => tx.addAuthorizers(addressBuffer(a.acct)))
const proposalKey = new Transaction.ProposalKey()
proposalKey.setAddress(addressBuffer(ix.proposer.addr))
proposalKey.setKeyId(ix.proposer.keyId)
proposalKey.setSequenceNumber(ix.proposer.sequenceNum)
tx.setProposalKey(proposalKey)
ix.authz.forEach(auth => {
if (auth.signature === null) return
const authzSig = new Transaction.Signature()
authzSig.setAddress(addressBuffer(auth.acct))
authzSig.setKeyId(auth.keyId)
authzSig.setSignature(hexBuffer(auth.signature))
tx.addPayloadSignatures(authzSig)
})
const payerSig = new AccountSignature()
payerSig.setAccount(addressToBuffer(bytes(ix.payer.acct, 20)))
payerSig.setSignature(ix.payer.signature)
const payerSignature = payerSig
const payerSig = new Transaction.Signature()
payerSig.setAddress(addressBuffer(ix.payer.acct))
payerSig.setKeyId(ix.payer.keyId)
payerSig.setSignature(hexBuffer(ix.payer.signature))
const transactionMsg = new TransactionMessage()
transactionMsg.setScript(scriptToBuffer(ix.payload.code))
transactionMsg.setNonce(ix.payload.nonce)
transactionMsg.setComputeLimit(ix.payload.limit)
transactionMsg.setReferenceBlockHash(
ix.payload.ref ? hashToBuffer(ix.payload.ref) : null
)
transactionMsg.setPayeraccount(addressToBuffer(bytes(ix.payer.acct, 20)))
ix.authz.forEach(a =>
transactionMsg.addScriptaccounts(addressToBuffer(bytes(a.acct, 20)))
)
accountSignatures.forEach(accountSignature =>
transactionMsg.addSignatures(accountSignature)
)
accountSignatures.push(payerSignature)
tx.addEnvelopeSignatures(payerSig)
const req = new SendTransactionRequest()
req.setTransaction(transactionMsg)
req.setTransaction(tx)
const res = await unary(opts.node, ObserveService.SendTransaction, req)
const res = await unary(opts.node, AccessAPI.SendTransaction, req)
let ret = response()
ret.tag = ix.tag
ret.transactionId = bufferToHexString(res.getHash_asU8())
ret.transactionHash = u8ToHex(res.getId_asU8())
return ret
}

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