Skip to content

Commit

Permalink
Merge 5083d39 into a33938c
Browse files Browse the repository at this point in the history
  • Loading branch information
keefertaylor authored Jul 27, 2020
2 parents a33938c + 5083d39 commit a35e248
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 19 additions & 4 deletions src/chain/tezos/TezosNodeWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,8 @@ export namespace TezosNodeWriter {
/**
* Dry run the given operation and return consumed resources.
*
* Note: Estimating an operation on an unrevealed account is not supported and will fail.
*
* TODO: Add support for estimating multiple operations so that reveals can be processed.
* Note: Estimating an operation on an unrevealed account is not supported and will fail. Use
* `estimateOperations` instead.
*
* @param {string} server Tezos node to connect to
* @param {string} chainid The chain ID to apply the operation on.
Expand All @@ -666,12 +665,28 @@ export namespace TezosNodeWriter {
server: string,
chainid: string,
operation: TezosP2PMessageTypes.Operation
): Promise<{ gas: number, storageCost: number }> {
return estimateOperations(server, chainid, [operation])
}

/**
* Dry run the given operations and return consumed resources.
*
* @param {string} server Tezos node to connect to
* @param {string} chainid The chain ID to apply the operation on.
* @param {TezosP2PMessageTypes.Operation} operations An array of operations to estimate.
* @returns A two-element object gas and storage costs. Throws an error if one was encountered.
*/
export async function estimateOperations(
server: string,
chainid: string,
operations: Array<TezosP2PMessageTypes.Operation>
): Promise<{ gas: number, storageCost: number }> {
const fake_signature = 'edsigu6xFLH2NpJ1VcYshpjW99Yc1TAL1m2XBqJyXrxcZQgBMo8sszw2zm626yjpA3pWMhjpsahLrWdmvX9cqhd4ZEUchuBuFYy';
const fake_chainid = 'NetXdQprcVkpaWU';
const fake_branch = 'BL94i2ShahPx3BoNs6tJdXDdGeoJ9ukwujUA2P8WJwULYNdimmq';

const response = await performPostRequest(server, `chains/${chainid}/blocks/head/helpers/scripts/run_operation`, { chain_id: fake_chainid, operation: { branch: fake_branch, contents: [operation], signature: fake_signature } });
const response = await performPostRequest(server, `chains/${chainid}/blocks/head/helpers/scripts/run_operation`, { chain_id: fake_chainid, operation: { branch: fake_branch, contents: operations, signature: fake_signature } });
const responseText = await response.text();

parseRPCError(responseText);
Expand Down

0 comments on commit a35e248

Please sign in to comment.