@onflow/send
Advanced tools
Comparing version 0.0.8 to 0.0.9
@@ -5,2 +5,9 @@ ### Unreleased | ||
### 0.0.9 -- 2020-05-04 | ||
- 2020-05-04 **BREAKING** -- VSN `@onflow/interaction` 0.0.5 -> 0.0.6 Breaking Change | ||
- 2020-05-04 **BREAKING** -- Updates send according to the updated interaction ADT | ||
- 2020-04-27 **BREAKING** -- Parses JSON-CDC payloads in `sendGetTransactionStatus` | ||
- 2020-04-23 **BREAKING** -- Parses JSON-CDC payloads before putting them in a response. | ||
### 0.0.8 -- 2020-04-20 | ||
@@ -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"),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.transactionId=(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(Buffer.from(e.txId,"hex")),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)}}; | ||
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")},c=function(e){return Buffer.from(e.padStart(40,0),"hex")},i=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.message.cadence,"utf8")),s.setGasLimit(e.message.computeLimit),s.setReferenceBlockId(e.message.refBlock?o(e.message.refBlock):null),s.setPayer(c(e.accounts[e.payer].addr)),e.authorizations.forEach(function(t){return s.addAuthorizers(c(e.accounts[t].addr))});var i=new t.Transaction.ProposalKey;i.setAddress(c(e.accounts[e.proposer].addr)),i.setKeyId(e.accounts[e.proposer].keyId),i.setSequenceNumber(e.accounts[e.proposer].sequenceNum),s.setProposalKey(i),e.authorizations.forEach(function(r){if(null!==e.accounts[r].signature){var n=new t.Transaction.Signature;n.setAddress(c(e.accounts[r].addr)),n.setKeyId(e.accounts[r].keyId),n.setSignature(o(e.accounts[r].signature)),s.addPayloadSignatures(n)}});var u=new t.Transaction.Signature;u.setAddress(c(e.accounts[e.payer].addr)),u.setKeyId(e.accounts[e.payer].keyId),u.setSignature(o(e.accounts[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.transactionId=(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(Buffer.from(e.transactionId,"hex")),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: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 Promise.resolve(function(e,n){void 0===n&&(n={});try{var s=new t.ExecuteScriptAtLatestBlockRequest,o=Buffer.from(e.message.cadence,"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=JSON.parse(Buffer.from(t.getValue_asU8()).toString("utf8")),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.accountAddr.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:i(s.getAddress_asU8()),balance:s.getBalance(),code:s.getCode_asU8(),keys:s.getKeysList().map(function(e){return{index:e.getIndex(),publicKey:i(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.events.eventType),s.setStartHeight(Number(e.events.start)),s.setEndHeight(Number(e.events.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.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 Promise.resolve(function(e,n){void 0===n&&(n={});try{var s=new t.GetLatestBlockRequest;return s.setIsSealed(e.latestBlock.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(),c=r.response();return c.tag=e.tag,c.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},c})}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 o,isGetTransactionStatus as a,isTransaction as s}from"@onflow/interaction";import{Transaction as i,SendTransactionRequest as u,AccessAPI as c,GetTransactionRequest as g,ExecuteScriptAtLatestBlockRequest as d,GetAccountRequest as f,GetEventsForHeightRangeRequest as l,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,o){h.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===h.Code.OK?n(e.message):o(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 o=new i.Signature;o.setAddress(S(e.payer.acct)),o.setKeyId(e.payer.keyId),o.setSignature(P(e.payer.signature)),r.addEnvelopeSignatures(o);var a=new u;return a.setTransaction(r),Promise.resolve(I(t.node,c.SendTransaction,a)).then(function(t){var r,n=v();return n.tag=e.tag,n.transactionId=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),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 g;return r.setId(Buffer.from(e.txId,"hex")),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 o(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 f;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 l;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(),o=r.getBlockSealsList(),a=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:o.map(function(e){return{blockId:b(e.getBlockId_asU8()),executionReceiptId:b(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},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}; | ||
import{isPing as e,isGetLatestBlock as t,isGetEvents as r,isGetAccount as n,isScript as o,isGetTransactionStatus as s,isTransaction as a}from"@onflow/interaction";import{Transaction as c,SendTransactionRequest as i,AccessAPI as u,GetTransactionRequest as g,ExecuteScriptAtLatestBlockRequest as d,GetAccountRequest as f,GetEventsForHeightRangeRequest as l,GetLatestBlockRequest as m,PingRequest as v}from"@onflow/protobuf";import{response as p}from"@onflow/response";import{grpc as h}from"@improbable-eng/grpc-web";import{NodeHttpTransport as S}from"@improbable-eng/grpc-web-node-http-transport";var y=function(e,t,r){try{return Promise.resolve(new Promise(function(n,o){h.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===h.Code.OK?n(e.message):o(new Error(t))}})}))}catch(e){return Promise.reject(e)}};h.setDefaultTransport(S());var I=function(e){return Buffer.from(e,"hex")},P=function(e){return Buffer.from(e.padStart(40,0),"hex")},B=function(e){return Buffer.from(e).toString("hex")},x=function(e){return Buffer.from(e).toString("hex")},k=function(h,S){void 0===S&&(S={});try{switch(!0){case a(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new c;r.setScript(Buffer.from(e.message.cadence,"utf8")),r.setGasLimit(e.message.computeLimit),r.setReferenceBlockId(e.message.refBlock?I(e.message.refBlock):null),r.setPayer(P(e.accounts[e.payer].addr)),e.authorizations.forEach(function(t){return r.addAuthorizers(P(e.accounts[t].addr))});var n=new c.ProposalKey;n.setAddress(P(e.accounts[e.proposer].addr)),n.setKeyId(e.accounts[e.proposer].keyId),n.setSequenceNumber(e.accounts[e.proposer].sequenceNum),r.setProposalKey(n),e.authorizations.forEach(function(t){if(null!==e.accounts[t].signature){var n=new c.Signature;n.setAddress(P(e.accounts[t].addr)),n.setKeyId(e.accounts[t].keyId),n.setSignature(I(e.accounts[t].signature)),r.addPayloadSignatures(n)}});var o=new c.Signature;o.setAddress(P(e.accounts[e.payer].addr)),o.setKeyId(e.accounts[e.payer].keyId),o.setSignature(I(e.accounts[e.payer].signature)),r.addEnvelopeSignatures(o);var s=new i;return s.setTransaction(r),Promise.resolve(y(t.node,u.SendTransaction,s)).then(function(t){var r,n=p();return n.tag=e.tag,n.transactionId=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),n})}catch(e){return Promise.reject(e)}}(h,S));case s(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new g;return r.setId(Buffer.from(e.transactionId,"hex")),Promise.resolve(y(t.node,u.GetTransactionResult,r)).then(function(t){var r=t.getEventsList(),n=p();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)}}(h,S));case o(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new d,n=Buffer.from(e.message.cadence,"utf8");return r.setScript(n),Promise.resolve(y(t.node,u.ExecuteScriptAtLatestBlock,r)).then(function(t){var r=p();return r.tag=e.tag,r.encodedData=JSON.parse(Buffer.from(t.getValue_asU8()).toString("utf8")),r})}catch(e){return Promise.reject(e)}}(h,S));case n(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new f;return r.setAddress(Buffer.from(e.accountAddr.padStart(40,0),"hex")),Promise.resolve(y(t.node,u.GetAccount,r)).then(function(t){var r=p();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)}}(h,S));case r(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new l;return r.setType(e.events.eventType),r.setStartHeight(Number(e.events.start)),r.setEndHeight(Number(e.events.end)),Promise.resolve(y(t.node,u.GetEventsForHeightRange,r)).then(function(t){var r=p();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)}}(h,S));case t(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new m;return r.setIsSealed(e.latestBlock.isSealed),Promise.resolve(y(t.node,u.GetLatestBlock,r)).then(function(t){var r=t.getBlock(),n=r.getCollectionGuaranteesList(),o=r.getBlockSealsList(),s=r.getSignaturesList(),a=p();return a.tag=e.tag,a.latestBlock={id:x(r.getId_asU8()),parentId:x(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:x(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:x(e.getBlockId_asU8()),executionReceiptId:x(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:s},a})}catch(e){return Promise.reject(e)}}(h,S));case e(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new v;return Promise.resolve(y(t.node,u.Ping,r)).then(function(t){var r=p();return r.tag=e.tag,r})}catch(e){return Promise.reject(e)}}(h,S));default:return Promise.resolve(h)}}catch(e){return Promise.reject(e)}};export{k 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 o,isGetTransactionStatus as a,isTransaction as s}from"@onflow/interaction";import{Transaction as i,SendTransactionRequest as u,AccessAPI as c,GetTransactionRequest as g,ExecuteScriptAtLatestBlockRequest as d,GetAccountRequest as f,GetEventsForHeightRangeRequest as l,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,o){h.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===h.Code.OK?n(e.message):o(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 o=new i.Signature;o.setAddress(S(e.payer.acct)),o.setKeyId(e.payer.keyId),o.setSignature(P(e.payer.signature)),r.addEnvelopeSignatures(o);var a=new u;return a.setTransaction(r),Promise.resolve(I(t.node,c.SendTransaction,a)).then(function(t){var r,n=v();return n.tag=e.tag,n.transactionId=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),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 g;return r.setId(Buffer.from(e.txId,"hex")),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 o(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 f;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 l;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(),o=r.getBlockSealsList(),a=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:o.map(function(e){return{blockId:b(e.getBlockId_asU8()),executionReceiptId:b(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:a},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}; | ||
import{isPing as e,isGetLatestBlock as t,isGetEvents as r,isGetAccount as n,isScript as o,isGetTransactionStatus as s,isTransaction as a}from"@onflow/interaction";import{Transaction as c,SendTransactionRequest as i,AccessAPI as u,GetTransactionRequest as g,ExecuteScriptAtLatestBlockRequest as d,GetAccountRequest as f,GetEventsForHeightRangeRequest as l,GetLatestBlockRequest as m,PingRequest as v}from"@onflow/protobuf";import{response as p}from"@onflow/response";import{grpc as h}from"@improbable-eng/grpc-web";import{NodeHttpTransport as S}from"@improbable-eng/grpc-web-node-http-transport";var y=function(e,t,r){try{return Promise.resolve(new Promise(function(n,o){h.unary(t,{request:r,host:e,onEnd:function(e){var t=e.statusMessage;e.status===h.Code.OK?n(e.message):o(new Error(t))}})}))}catch(e){return Promise.reject(e)}};h.setDefaultTransport(S());var I=function(e){return Buffer.from(e,"hex")},P=function(e){return Buffer.from(e.padStart(40,0),"hex")},B=function(e){return Buffer.from(e).toString("hex")},x=function(e){return Buffer.from(e).toString("hex")},k=function(h,S){void 0===S&&(S={});try{switch(!0){case a(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new c;r.setScript(Buffer.from(e.message.cadence,"utf8")),r.setGasLimit(e.message.computeLimit),r.setReferenceBlockId(e.message.refBlock?I(e.message.refBlock):null),r.setPayer(P(e.accounts[e.payer].addr)),e.authorizations.forEach(function(t){return r.addAuthorizers(P(e.accounts[t].addr))});var n=new c.ProposalKey;n.setAddress(P(e.accounts[e.proposer].addr)),n.setKeyId(e.accounts[e.proposer].keyId),n.setSequenceNumber(e.accounts[e.proposer].sequenceNum),r.setProposalKey(n),e.authorizations.forEach(function(t){if(null!==e.accounts[t].signature){var n=new c.Signature;n.setAddress(P(e.accounts[t].addr)),n.setKeyId(e.accounts[t].keyId),n.setSignature(I(e.accounts[t].signature)),r.addPayloadSignatures(n)}});var o=new c.Signature;o.setAddress(P(e.accounts[e.payer].addr)),o.setKeyId(e.accounts[e.payer].keyId),o.setSignature(I(e.accounts[e.payer].signature)),r.addEnvelopeSignatures(o);var s=new i;return s.setTransaction(r),Promise.resolve(y(t.node,u.SendTransaction,s)).then(function(t){var r,n=p();return n.tag=e.tag,n.transactionId=(r=t.getId_asU8(),Buffer.from(r).toString("hex")),n})}catch(e){return Promise.reject(e)}}(h,S));case s(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new g;return r.setId(Buffer.from(e.transactionId,"hex")),Promise.resolve(y(t.node,u.GetTransactionResult,r)).then(function(t){var r=t.getEventsList(),n=p();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)}}(h,S));case o(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new d,n=Buffer.from(e.message.cadence,"utf8");return r.setScript(n),Promise.resolve(y(t.node,u.ExecuteScriptAtLatestBlock,r)).then(function(t){var r=p();return r.tag=e.tag,r.encodedData=JSON.parse(Buffer.from(t.getValue_asU8()).toString("utf8")),r})}catch(e){return Promise.reject(e)}}(h,S));case n(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new f;return r.setAddress(Buffer.from(e.accountAddr.padStart(40,0),"hex")),Promise.resolve(y(t.node,u.GetAccount,r)).then(function(t){var r=p();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)}}(h,S));case r(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new l;return r.setType(e.events.eventType),r.setStartHeight(Number(e.events.start)),r.setEndHeight(Number(e.events.end)),Promise.resolve(y(t.node,u.GetEventsForHeightRange,r)).then(function(t){var r=p();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)}}(h,S));case t(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new m;return r.setIsSealed(e.latestBlock.isSealed),Promise.resolve(y(t.node,u.GetLatestBlock,r)).then(function(t){var r=t.getBlock(),n=r.getCollectionGuaranteesList(),o=r.getBlockSealsList(),s=r.getSignaturesList(),a=p();return a.tag=e.tag,a.latestBlock={id:x(r.getId_asU8()),parentId:x(r.getParentId_asU8()),height:r.getHeight(),timestamp:r.getTimestamp(),collectionGuarantees:n.map(function(e){return{collectionId:x(e.getCollectionId_asU8()),signatures:e.getSignaturesList()}}),blockSeals:o.map(function(e){return{blockId:x(e.getBlockId_asU8()),executionReceiptId:x(e.getExecutionReceiptId_asU8()),executionReceiptSignatures:e.getExecutionReceiptSignaturesList(),resultApprovalSignatures:e.getResultApprovalSignaturesList()}}),signatures:s},a})}catch(e){return Promise.reject(e)}}(h,S));case e(h):return Promise.resolve(function(e,t){void 0===t&&(t={});try{var r=new v;return Promise.resolve(y(t.node,u.Ping,r)).then(function(t){var r=p();return r.tag=e.tag,r})}catch(e){return Promise.reject(e)}}(h,S));default:return Promise.resolve(h)}}catch(e){return Promise.reject(e)}};export{k 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")):"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.transactionId=(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(Buffer.from(e.txId,"hex")),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)}}}); | ||
!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 c=function(e){return Buffer.from(e,"hex")},i=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.message.cadence,"utf8")),s.setGasLimit(e.message.computeLimit),s.setReferenceBlockId(e.message.refBlock?c(e.message.refBlock):null),s.setPayer(i(e.accounts[e.payer].addr)),e.authorizations.forEach(function(t){return s.addAuthorizers(i(e.accounts[t].addr))});var o=new r.Transaction.ProposalKey;o.setAddress(i(e.accounts[e.proposer].addr)),o.setKeyId(e.accounts[e.proposer].keyId),o.setSequenceNumber(e.accounts[e.proposer].sequenceNum),s.setProposalKey(o),e.authorizations.forEach(function(t){if(null!==e.accounts[t].signature){var n=new r.Transaction.Signature;n.setAddress(i(e.accounts[t].addr)),n.setKeyId(e.accounts[t].keyId),n.setSignature(c(e.accounts[t].signature)),s.addPayloadSignatures(n)}});var u=new r.Transaction.Signature;u.setAddress(i(e.accounts[e.payer].addr)),u.setKeyId(e.accounts[e.payer].keyId),u.setSignature(c(e.accounts[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.transactionId=(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(Buffer.from(e.transactionId,"hex")),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:JSON.parse(Buffer.from(e.getPayload_asU8()).toString("utf8"))};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.message.cadence,"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=JSON.parse(Buffer.from(t.getValue_asU8()).toString("utf8")),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.accountAddr.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.events.eventType),s.setStartHeight(Number(e.events.start)),s.setEndHeight(Number(e.events.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.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,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.latestBlock.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(),c=n.response();return c.tag=e.tag,c.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},c})}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.8", | ||
"version": "0.0.9", | ||
"description": "Flow SDK Send", | ||
@@ -37,5 +37,5 @@ "license": "Apache-2.0", | ||
"dependencies": { | ||
"@improbable-eng/grpc-web": "^0.12.0", | ||
"@improbable-eng/grpc-web-node-http-transport": "^0.12.0", | ||
"@onflow/interaction": "0.0.5", | ||
"@improbable-eng/grpc-web": "0.12.0", | ||
"@improbable-eng/grpc-web-node-http-transport": "0.12.0", | ||
"@onflow/interaction": "0.0.6", | ||
"@onflow/protobuf": "0.1.2", | ||
@@ -42,0 +42,0 @@ "@onflow/response": "0.0.2" |
@@ -7,2 +7,14 @@ # @onflow/send | ||
# Status | ||
- **Last Updated:** April 21st 2020 | ||
- **Stable:** Yes | ||
- **Risk of Breaking Change:** Low (If taking into account the known upcoming changes) | ||
Other than taking on the reponsibility of unpacking the JSON-CDC encodedData in the response, this package is nearing its first major release. | ||
Known Upcoming Changes: | ||
- Send will be unpacking the JSON-CDC encodedData | ||
# Install | ||
@@ -9,0 +21,0 @@ |
@@ -7,3 +7,3 @@ import {ExecuteScriptAtLatestBlockRequest, AccessAPI} from "@onflow/protobuf" | ||
const req = new ExecuteScriptAtLatestBlockRequest() | ||
const code = Buffer.from(ix.payload.code, "utf8") | ||
const code = Buffer.from(ix.message.cadence, "utf8") | ||
req.setScript(code) | ||
@@ -15,5 +15,5 @@ | ||
ret.tag = ix.tag | ||
ret.encodedData = res.getValue_asU8() | ||
ret.encodedData = JSON.parse(Buffer.from(res.getValue_asU8()).toString("utf8")) | ||
return ret | ||
} |
@@ -13,3 +13,3 @@ import {GetAccountRequest, AccessAPI} from "@onflow/protobuf" | ||
const req = new GetAccountRequest() | ||
req.setAddress(addressBuffer(ix.acct)) | ||
req.setAddress(addressBuffer(ix.accountAddr)) | ||
@@ -16,0 +16,0 @@ const res = await unary(opts.node, AccessAPI.GetAccount, req) |
@@ -9,5 +9,5 @@ import {GetEventsForHeightRangeRequest, AccessAPI} from "@onflow/protobuf" | ||
const req = new GetEventsForHeightRangeRequest() | ||
req.setType(ix.eventType) | ||
req.setStartHeight(Number(ix.bounds.start)) | ||
req.setEndHeight(Number(ix.bounds.end)) | ||
req.setType(ix.events.eventType) | ||
req.setStartHeight(Number(ix.events.start)) | ||
req.setEndHeight(Number(ix.events.end)) | ||
@@ -20,8 +20,10 @@ const res = await unary(opts.node, AccessAPI.GetEventsForHeightRange, req) | ||
const results = res.getResultsList() | ||
ret.events = results.map(result => { | ||
ret.events = results.reduce((blocks, result) => { | ||
const blockId = result.getBlockId() | ||
const blockHeight = result.getBlockHeight() | ||
const events = result.getEventsList() | ||
return { | ||
blockId: result.getBlockId(), | ||
blockHeight: result.getBlockHeight(), | ||
events: events.map(event => ({ | ||
events.forEach(event => { | ||
blocks.push({ | ||
blockId, | ||
blockHeight, | ||
type: event.getType(), | ||
@@ -31,8 +33,9 @@ transactionId: u8ToHex(event.getTransactionId_asU8()), | ||
eventIndex: event.getEventIndex(), | ||
payload: event.getPayload_asU8(), | ||
})), | ||
} | ||
}) | ||
payload: JSON.parse(Buffer.from(event.getPayload_asU8()).toString("utf8")), | ||
}) | ||
}) | ||
return blocks | ||
}, []) | ||
return ret | ||
} |
@@ -9,3 +9,3 @@ import {GetLatestBlockRequest, AccessAPI} from "@onflow/protobuf" | ||
const req = new GetLatestBlockRequest() | ||
req.setIsSealed(ix.isSealed) | ||
req.setIsSealed(ix.latestBlock.isSealed) | ||
@@ -12,0 +12,0 @@ const res = await unary(opts.node, AccessAPI.GetLatestBlock, req) |
@@ -10,3 +10,3 @@ import {AccessAPI, GetTransactionRequest} from "@onflow/protobuf" | ||
const req = new GetTransactionRequest() | ||
req.setId(hexBuffer(ix.txId)) | ||
req.setId(hexBuffer(ix.transactionId)) | ||
@@ -28,3 +28,3 @@ const res = await unary(opts.node, AccessAPI.GetTransactionResult, req) | ||
eventIndex: event.getEventIndex(), | ||
payload: event.getPayload_asU8(), | ||
payload: JSON.parse(Buffer.from(event.getPayload_asU8()).toString("utf8")), | ||
})), | ||
@@ -31,0 +31,0 @@ } |
@@ -14,21 +14,21 @@ import {AccessAPI, Transaction, SendTransactionRequest} from "@onflow/protobuf" | ||
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))) | ||
tx.setScript(scriptBuffer(ix.message.cadence)) | ||
tx.setGasLimit(ix.message.computeLimit) | ||
tx.setReferenceBlockId(ix.message.refBlock ? hexBuffer(ix.message.refBlock) : null) | ||
tx.setPayer(addressBuffer(ix.accounts[ix.payer].addr)) | ||
ix.authorizations.forEach(tempId => tx.addAuthorizers(addressBuffer(ix.accounts[tempId].addr))) | ||
const proposalKey = new Transaction.ProposalKey() | ||
proposalKey.setAddress(addressBuffer(ix.proposer.addr)) | ||
proposalKey.setKeyId(ix.proposer.keyId) | ||
proposalKey.setSequenceNumber(ix.proposer.sequenceNum) | ||
proposalKey.setAddress(addressBuffer(ix.accounts[ix.proposer].addr)) | ||
proposalKey.setKeyId(ix.accounts[ix.proposer].keyId) | ||
proposalKey.setSequenceNumber(ix.accounts[ix.proposer].sequenceNum) | ||
tx.setProposalKey(proposalKey) | ||
ix.authz.forEach(auth => { | ||
if (auth.signature === null) return | ||
ix.authorizations.forEach(tempId => { | ||
if (ix.accounts[tempId].signature === null) return | ||
const authzSig = new Transaction.Signature() | ||
authzSig.setAddress(addressBuffer(auth.acct)) | ||
authzSig.setKeyId(auth.keyId) | ||
authzSig.setSignature(hexBuffer(auth.signature)) | ||
authzSig.setAddress(addressBuffer(ix.accounts[tempId].addr)) | ||
authzSig.setKeyId(ix.accounts[tempId].keyId) | ||
authzSig.setSignature(hexBuffer(ix.accounts[tempId].signature)) | ||
@@ -39,5 +39,5 @@ tx.addPayloadSignatures(authzSig) | ||
const payerSig = new Transaction.Signature() | ||
payerSig.setAddress(addressBuffer(ix.payer.acct)) | ||
payerSig.setKeyId(ix.payer.keyId) | ||
payerSig.setSignature(hexBuffer(ix.payer.signature)) | ||
payerSig.setAddress(addressBuffer(ix.accounts[ix.payer].addr)) | ||
payerSig.setKeyId(ix.accounts[ix.payer].keyId) | ||
payerSig.setSignature(hexBuffer(ix.accounts[ix.payer].signature)) | ||
@@ -44,0 +44,0 @@ tx.addEnvelopeSignatures(payerSig) |
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
107983
340
36
+ Added@onflow/interaction@0.0.6(transitive)
- Removed@onflow/interaction@0.0.5(transitive)
Updated@onflow/interaction@0.0.6