diff --git a/packages/dag4-network/src/api/v2/l1-api.ts b/packages/dag4-network/src/api/v2/l1-api.ts index cd2cc9a..3b8cd78 100644 --- a/packages/dag4-network/src/api/v2/l1-api.ts +++ b/packages/dag4-network/src/api/v2/l1-api.ts @@ -90,8 +90,8 @@ class L1Api { ); } - async postAllowSpend(signedAllowSpend: SignedAllowSpend) { - return this.service.$post(`/allow-spends`, signedAllowSpend); + async postAllowSpend(signedAllowSpend: SignedAllowSpend, params?: Record) { + return this.service.$post(`/allow-spends`, signedAllowSpend, {}, params); } async getTokenLockLastRef(address: string) { @@ -100,16 +100,16 @@ class L1Api { ); } - async postTokenLock(signedTokenLock: SignedTokenLock) { - return this.service.$post(`/token-locks`, signedTokenLock); + async postTokenLock(signedTokenLock: SignedTokenLock, params?: Record) { + return this.service.$post(`/token-locks`, signedTokenLock, {}, params); } async getPendingTransaction(hash: string) { return this.service.$get(`/transactions/${hash}`); } - async postTransaction(tx: PostTransactionV2) { - return this.service.$post("/transactions", tx); + async postTransaction(tx: PostTransactionV2, params?: Record) { + return this.service.$post("/transactions", tx, {}, params); } async getClusterInfo(): Promise { diff --git a/packages/dag4-network/src/dag-network.ts b/packages/dag4-network/src/dag-network.ts index 5671429..e37340f 100644 --- a/packages/dag4-network/src/dag-network.ts +++ b/packages/dag4-network/src/dag-network.ts @@ -124,9 +124,9 @@ export class DagNetwork { return this.blockExplorerApi.getTransaction(hash); } - async postTransaction(tx: PostTransaction | PostTransactionV2): Promise { + async postTransaction(tx: PostTransaction | PostTransactionV2, params?: Record): Promise { if (this.getNetworkVersion() === '2.0') { - const response = await this.l1Api.postTransaction(tx as PostTransactionV2) as any; + const response = await this.l1Api.postTransaction(tx as PostTransactionV2, params) as any; // Support data/meta format and object return format return response.data ? response.data.hash : response.hash; diff --git a/packages/dag4-network/src/metagraph-token-network.ts b/packages/dag4-network/src/metagraph-token-network.ts index 30d2ac7..04f396f 100644 --- a/packages/dag4-network/src/metagraph-token-network.ts +++ b/packages/dag4-network/src/metagraph-token-network.ts @@ -150,9 +150,10 @@ class MetagraphTokenNetwork { return response ? response.data : null; } - async postTransaction(tx: PostTransactionV2): Promise { + async postTransaction(tx: PostTransactionV2, params?: Record): Promise { const response = (await this.l1Api.postTransaction( - tx as PostTransactionV2 + tx as PostTransactionV2, + params )) as any; // Support data/meta format and object return format diff --git a/packages/dag4-wallet/src/dag-account.ts b/packages/dag4-wallet/src/dag-account.ts index f8d6768..3332747 100644 --- a/packages/dag4-wallet/src/dag-account.ts +++ b/packages/dag4-wallet/src/dag-account.ts @@ -358,7 +358,8 @@ export class DagAccount { toAddress: string, amount: number, fee = 0, - autoEstimateFee = false + autoEstimateFee = false, + params?: Record ): Promise { let normalizedAmount = Math.floor( new BigNumber(amount).multipliedBy(DAG_DECIMALS).toNumber() @@ -385,7 +386,7 @@ export class DagAccount { } const tx = await this.generateSignedTransaction(toAddress, amount, fee); - const txHash = await this.network.postTransaction(tx); + const txHash = await this.network.postTransaction(tx, params); if (txHash) { return { @@ -633,7 +634,7 @@ export class DagAccount { return allowSpendResponse; } - async createAllowSpend(body: AllowSpend) { + async createAllowSpend(body: AllowSpend, params?: Record) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -646,7 +647,7 @@ export class DagAccount { currencyId: null, }; - return allowSpend(bodyWithCurrencyId, this.network, this.keyTrio); + return allowSpend(bodyWithCurrencyId, this.network, this.keyTrio, params); } /** @@ -735,7 +736,7 @@ export class DagAccount { return tokenLockResponse; } - async createTokenLock(body: TokenLock) { + async createTokenLock(body: TokenLock, params?: Record) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -748,7 +749,7 @@ export class DagAccount { currencyId: null, }; - return tokenLock(bodyWithCurrencyId, this.network, this.keyTrio); + return tokenLock(bodyWithCurrencyId, this.network, this.keyTrio, params); } /** diff --git a/packages/dag4-wallet/src/metagraph-token-client.ts b/packages/dag4-wallet/src/metagraph-token-client.ts index 5ac3574..813580a 100644 --- a/packages/dag4-wallet/src/metagraph-token-client.ts +++ b/packages/dag4-wallet/src/metagraph-token-client.ts @@ -115,7 +115,8 @@ class MetagraphTokenClient { toAddress: string, amount: number, fee = 0, - autoEstimateFee = false + autoEstimateFee = false, + params?: Record ): Promise { let normalizedAmount = Math.floor( new BigNumber(amount).multipliedBy(this.tokenDecimals).toNumber() @@ -152,7 +153,7 @@ class MetagraphTokenClient { throw new Error("Unable to post v1 transaction"); } - const txHash = await this.network.postTransaction(tx); + const txHash = await this.network.postTransaction(tx, params); if (txHash) { return { @@ -249,7 +250,7 @@ class MetagraphTokenClient { return this.sendBatchTransactions(txns); } - async createAllowSpend(body: AllowSpend) { + async createAllowSpend(body: AllowSpend, params?: Record) { this.account.assertAccountIsActive(); this.account.assertValidPrivateKey(); @@ -262,10 +263,10 @@ class MetagraphTokenClient { currencyId: this.networkInfo.metagraphId, }; - return allowSpend(bodyWithCurrencyId, this.network, this.account.keyTrio); + return allowSpend(bodyWithCurrencyId, this.network, this.account.keyTrio, params); } - async createTokenLock(body: TokenLock) { + async createTokenLock(body: TokenLock, params?: Record) { this.account.assertAccountIsActive(); this.account.assertValidPrivateKey(); @@ -278,7 +279,7 @@ class MetagraphTokenClient { currencyId: this.networkInfo.metagraphId, }; - return tokenLock(bodyWithCurrencyId, this.network, this.account.keyTrio); + return tokenLock(bodyWithCurrencyId, this.network, this.account.keyTrio, params); } async getDataFeeEstimate(data: any) { diff --git a/packages/dag4-wallet/src/shared/operations.ts b/packages/dag4-wallet/src/shared/operations.ts index 57d3d50..4beefc2 100644 --- a/packages/dag4-wallet/src/shared/operations.ts +++ b/packages/dag4-wallet/src/shared/operations.ts @@ -25,7 +25,8 @@ type SharedNetwork = DagNetwork | GlobalDagNetwork | MetagraphTokenNetwork; export const allowSpend = async ( body: AllowSpendWithCurrencyId, network: SharedNetwork, - keyTrio: KeyTrio + keyTrio: KeyTrio, + params?: Record ): Promise => { validateSchema(body, allowSpendSchema, true); @@ -82,7 +83,7 @@ export const allowSpend = async ( try { // Post signed allow spend body - allowSpendResponse = await network.l1Api.postAllowSpend(signedAllowSpend); + allowSpendResponse = await network.l1Api.postAllowSpend(signedAllowSpend, params); } catch (err) { console.error("Error sending the allow spend transaction"); throw err; @@ -98,7 +99,8 @@ export const allowSpend = async ( export const tokenLock = async ( body: TokenLockWithCurrencyId, network: SharedNetwork, - keyTrio: KeyTrio + keyTrio: KeyTrio, + params?: Record ): Promise => { validateSchema(body, tokenLockSchema, true); @@ -148,7 +150,7 @@ export const tokenLock = async ( try { // Post signed token lock body - tokenLockResponse = await network.l1Api.postTokenLock(signedTokenLock); + tokenLockResponse = await network.l1Api.postTokenLock(signedTokenLock, params); } catch (err) { console.error("Error sending the token lock transaction"); throw err;