Skip to content

Commit

Permalink
Merge 7b38c5a into e280b3e
Browse files Browse the repository at this point in the history
  • Loading branch information
elkesrio committed Nov 18, 2020
2 parents e280b3e + 7b38c5a commit cb37866
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions src/chain/tezos/TezosNodeWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,8 @@ export namespace TezosNodeWriter {
storageCost: resources.storageCost + fixedOriginationStorageCost
}
}

/**
* Dry run the given operation and return consumed resources.
*
* Note: Estimating an operation on an unrevealed account is not supported and will fail. Remember to prepend
* the Reveal operation if required.
* Dry run the given operation
*
* @param {string} server Tezos node to connect to
* @param {string} chainid The chain ID to apply the operation on.
Expand All @@ -666,16 +662,7 @@ export namespace TezosNodeWriter {
chainid: string,
...operations: 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: operations, signature: fake_signature } });
const responseText = await response.text();

parseRPCError(responseText);

const responseJSON = JSON.parse(responseText);
const responseJSON = dryRunOperation(server, chainid, ...operations);

let gas = 0;
let storageCost = 0;
Expand All @@ -701,6 +688,36 @@ export namespace TezosNodeWriter {
return { gas, storageCost };
}

/**
* Dry run the given operation and return consumed resources.
*
* Note: Estimating an operation on an unrevealed account is not supported and will fail. Remember to prepend
* the Reveal operation if required.
* @param {string} server Tezos node to connect to
* @param {string} chainid The chain ID to apply the operation on.
* @param {TezosP2PMessageTypes.Operation} operations A set of operations to update.
* @returns {Promise<object>} JSON-encoded response
*/
export async function dryRunOperation(
server: string,
chainid: string,
...operations: TezosP2PMessageTypes.Operation[]
): Promise<Response> {
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: operations, signature: fake_signature } });
const responseText = await response.text();

parseRPCError(responseText);

const responseJSON = JSON.parse(responseText);

return responseJSON;
}

/**
* This function checks if the server response contains an error. There are multiple formats for errors coming
* back from the server, this method attempts to normalized them for downstream parsing.
Expand Down

0 comments on commit cb37866

Please sign in to comment.