From c164729eec70d4d680b2d814c71160da2f6f41cf Mon Sep 17 00:00:00 2001 From: joepetrowski Date: Sat, 30 May 2020 13:35:15 +0200 Subject: [PATCH] add fee prediction endpoint --- src/util/util.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/util/util.ts b/src/util/util.ts index 0a079f8..8f1f1fb 100644 --- a/src/util/util.ts +++ b/src/util/util.ts @@ -168,12 +168,21 @@ export async function getClaimType(sidecarHost: string, address: string): Promis return claimsType.type; } +// Submit a transaction over Sidecar to the transaction queue. export async function submitTransaction(sidecarHost: string, encodedTx: string): Promise { const endpoint = `${sidecarHost}tx/`; const submission = await sidecarPost(endpoint, encodedTx); return submission; } +// Submit a transaction and ask for a transaction fee estimate. Do not submit the transaction to the +// transaction queue. +export async function getFeeEstimate(sidecarHost: string, encodedTx: string): Promise { + const endpoint = `${sidecarHost}tx/fee-estimate/`; + const dispatchInfo = await sidecarPost(endpoint, encodedTx); + return dispatchInfo; +} + /* Signing utilities */ // Ask the user to supply a signature and wait for the response. @@ -235,11 +244,20 @@ async function sidecarPost(url: string, tx: string): Promise { }, ) .then(({ data }) => data) - .then(({ cause, data, error, hash }) => { + .then(({ cause, data, error, hash, weight, partialFee }) => { if (cause || error) { throw new Error(`${cause}: ${error} (${data})`); } - return hash; + if (hash) { + return hash; + } + + if (partialFee) { + return { + weight, + partialFee + }; + } }); }