From 581e133d82b945e2686a2eb0c373ba89074df7dc Mon Sep 17 00:00:00 2001 From: Juan Olmedo Date: Tue, 26 Aug 2025 18:29:47 -0300 Subject: [PATCH 1/3] feat: add params on POST requests in the L1 API --- packages/dag4-network/src/api/v2/l1-api.ts | 14 +++++++------- packages/dag4-wallet/src/dag-account.ts | 10 +++++----- packages/dag4-wallet/src/metagraph-token-client.ts | 10 +++++----- packages/dag4-wallet/src/shared/operations.ts | 13 +++++++++---- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/packages/dag4-network/src/api/v2/l1-api.ts b/packages/dag4-network/src/api/v2/l1-api.ts index cd2cc9a..e9bbe99 100644 --- a/packages/dag4-network/src/api/v2/l1-api.ts +++ b/packages/dag4-network/src/api/v2/l1-api.ts @@ -1,4 +1,4 @@ -import { RestApi } from "@stardust-collective/dag4-core"; +import { RestApi, RestApiOptions } from "@stardust-collective/dag4-core"; import { DNC } from "../../DNC"; import { ClusterInfoV2, @@ -90,8 +90,8 @@ class L1Api { ); } - async postAllowSpend(signedAllowSpend: SignedAllowSpend) { - return this.service.$post(`/allow-spends`, signedAllowSpend); + async postAllowSpend(signedAllowSpend: SignedAllowSpend, params?: Record, options?: RestApiOptions) { + return this.service.$post(`/allow-spends`, signedAllowSpend, options, 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, options?: RestApiOptions) { + return this.service.$post(`/token-locks`, signedTokenLock, options, 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, options?: RestApiOptions) { + return this.service.$post("/transactions", tx, options, params); } async getClusterInfo(): Promise { diff --git a/packages/dag4-wallet/src/dag-account.ts b/packages/dag4-wallet/src/dag-account.ts index f8d6768..2a33130 100644 --- a/packages/dag4-wallet/src/dag-account.ts +++ b/packages/dag4-wallet/src/dag-account.ts @@ -1,4 +1,4 @@ -import { DAG_DECIMALS } from "@stardust-collective/dag4-core"; +import { DAG_DECIMALS, RestApiOptions } from "@stardust-collective/dag4-core"; import { keyStore, KeyTrio, @@ -633,7 +633,7 @@ export class DagAccount { return allowSpendResponse; } - async createAllowSpend(body: AllowSpend) { + async createAllowSpend(body: AllowSpend, params?: Record, options?: RestApiOptions) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -646,7 +646,7 @@ export class DagAccount { currencyId: null, }; - return allowSpend(bodyWithCurrencyId, this.network, this.keyTrio); + return allowSpend(bodyWithCurrencyId, this.network, this.keyTrio, params, options); } /** @@ -735,7 +735,7 @@ export class DagAccount { return tokenLockResponse; } - async createTokenLock(body: TokenLock) { + async createTokenLock(body: TokenLock, params?: Record, options?: RestApiOptions) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -748,7 +748,7 @@ export class DagAccount { currencyId: null, }; - return tokenLock(bodyWithCurrencyId, this.network, this.keyTrio); + return tokenLock(bodyWithCurrencyId, this.network, this.keyTrio, params, options); } /** diff --git a/packages/dag4-wallet/src/metagraph-token-client.ts b/packages/dag4-wallet/src/metagraph-token-client.ts index 5ac3574..1bd48a0 100644 --- a/packages/dag4-wallet/src/metagraph-token-client.ts +++ b/packages/dag4-wallet/src/metagraph-token-client.ts @@ -1,4 +1,4 @@ -import { DAG_DECIMALS } from "@stardust-collective/dag4-core"; +import { DAG_DECIMALS, RestApiOptions } from "@stardust-collective/dag4-core"; import { PostTransactionV2 } from "@stardust-collective/dag4-keystore"; import { ActionType, @@ -249,7 +249,7 @@ class MetagraphTokenClient { return this.sendBatchTransactions(txns); } - async createAllowSpend(body: AllowSpend) { + async createAllowSpend(body: AllowSpend, params?: Record, options?: RestApiOptions) { this.account.assertAccountIsActive(); this.account.assertValidPrivateKey(); @@ -262,10 +262,10 @@ class MetagraphTokenClient { currencyId: this.networkInfo.metagraphId, }; - return allowSpend(bodyWithCurrencyId, this.network, this.account.keyTrio); + return allowSpend(bodyWithCurrencyId, this.network, this.account.keyTrio, params, options); } - async createTokenLock(body: TokenLock) { + async createTokenLock(body: TokenLock, params?: Record, options?: RestApiOptions) { this.account.assertAccountIsActive(); this.account.assertValidPrivateKey(); @@ -278,7 +278,7 @@ class MetagraphTokenClient { currencyId: this.networkInfo.metagraphId, }; - return tokenLock(bodyWithCurrencyId, this.network, this.account.keyTrio); + return tokenLock(bodyWithCurrencyId, this.network, this.account.keyTrio, params, options); } async getDataFeeEstimate(data: any) { diff --git a/packages/dag4-wallet/src/shared/operations.ts b/packages/dag4-wallet/src/shared/operations.ts index 57d3d50..c24a345 100644 --- a/packages/dag4-wallet/src/shared/operations.ts +++ b/packages/dag4-wallet/src/shared/operations.ts @@ -19,13 +19,16 @@ import { validateArraySchema, validateSchema, } from "../validationSchemas"; +import { RestApiOptions } from "@stardust-collective/dag4-core"; type SharedNetwork = DagNetwork | GlobalDagNetwork | MetagraphTokenNetwork; export const allowSpend = async ( body: AllowSpendWithCurrencyId, network: SharedNetwork, - keyTrio: KeyTrio + keyTrio: KeyTrio, + params?: Record, + options?: RestApiOptions ): Promise => { validateSchema(body, allowSpendSchema, true); @@ -82,7 +85,7 @@ export const allowSpend = async ( try { // Post signed allow spend body - allowSpendResponse = await network.l1Api.postAllowSpend(signedAllowSpend); + allowSpendResponse = await network.l1Api.postAllowSpend(signedAllowSpend, params, options); } catch (err) { console.error("Error sending the allow spend transaction"); throw err; @@ -98,7 +101,9 @@ export const allowSpend = async ( export const tokenLock = async ( body: TokenLockWithCurrencyId, network: SharedNetwork, - keyTrio: KeyTrio + keyTrio: KeyTrio, + params?: Record, + options?: RestApiOptions ): Promise => { validateSchema(body, tokenLockSchema, true); @@ -148,7 +153,7 @@ export const tokenLock = async ( try { // Post signed token lock body - tokenLockResponse = await network.l1Api.postTokenLock(signedTokenLock); + tokenLockResponse = await network.l1Api.postTokenLock(signedTokenLock, params, options); } catch (err) { console.error("Error sending the token lock transaction"); throw err; From 3cea5b15575b954545cbe418b778b32780b61478 Mon Sep 17 00:00:00 2001 From: Juan Olmedo Date: Wed, 27 Aug 2025 10:07:36 -0300 Subject: [PATCH 2/3] feat: add params on post transaction --- packages/dag4-network/src/dag-network.ts | 5 +++-- packages/dag4-network/src/metagraph-token-network.ts | 7 +++++-- packages/dag4-wallet/src/dag-account.ts | 6 ++++-- packages/dag4-wallet/src/metagraph-token-client.ts | 6 ++++-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/dag4-network/src/dag-network.ts b/packages/dag4-network/src/dag-network.ts index 5671429..ef54125 100644 --- a/packages/dag4-network/src/dag-network.ts +++ b/packages/dag4-network/src/dag-network.ts @@ -7,6 +7,7 @@ import { L1Api } from './api/v2/l1-api'; import { CbTransaction, PostTransaction, Snapshot, Transaction } from './dto/v1'; import { PendingTransaction, PostTransactionV2, SnapshotV2, TransactionV2 } from './dto/v2'; import { NetworkInfo } from './types/network-info'; +import { RestApiOptions } from '@stardust-collective/dag4-core'; export class DagNetwork { private connectedNetwork: NetworkInfo = { @@ -124,9 +125,9 @@ export class DagNetwork { return this.blockExplorerApi.getTransaction(hash); } - async postTransaction(tx: PostTransaction | PostTransactionV2): Promise { + async postTransaction(tx: PostTransaction | PostTransactionV2, params?: Record, options?: RestApiOptions): 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, options) 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..2123216 100644 --- a/packages/dag4-network/src/metagraph-token-network.ts +++ b/packages/dag4-network/src/metagraph-token-network.ts @@ -1,3 +1,4 @@ +import { RestApiOptions } from "@stardust-collective/dag4-core"; import { MetagraphTokenDataL1Api } from "./api/metagraph-token/data-l1-api"; import { MetagraphTokenL0Api } from "./api/metagraph-token/l0-api"; import { MetagraphTokenL1Api } from "./api/metagraph-token/l1-api"; @@ -150,9 +151,11 @@ class MetagraphTokenNetwork { return response ? response.data : null; } - async postTransaction(tx: PostTransactionV2): Promise { + async postTransaction(tx: PostTransactionV2, params?: Record, options?: RestApiOptions): Promise { const response = (await this.l1Api.postTransaction( - tx as PostTransactionV2 + tx as PostTransactionV2, + params, + options )) 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 2a33130..90bd6ca 100644 --- a/packages/dag4-wallet/src/dag-account.ts +++ b/packages/dag4-wallet/src/dag-account.ts @@ -358,7 +358,9 @@ export class DagAccount { toAddress: string, amount: number, fee = 0, - autoEstimateFee = false + autoEstimateFee = false, + params?: Record, + options?: RestApiOptions ): Promise { let normalizedAmount = Math.floor( new BigNumber(amount).multipliedBy(DAG_DECIMALS).toNumber() @@ -385,7 +387,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, options); if (txHash) { return { diff --git a/packages/dag4-wallet/src/metagraph-token-client.ts b/packages/dag4-wallet/src/metagraph-token-client.ts index 1bd48a0..7261809 100644 --- a/packages/dag4-wallet/src/metagraph-token-client.ts +++ b/packages/dag4-wallet/src/metagraph-token-client.ts @@ -115,7 +115,9 @@ class MetagraphTokenClient { toAddress: string, amount: number, fee = 0, - autoEstimateFee = false + autoEstimateFee = false, + params?: Record, + options?: RestApiOptions ): Promise { let normalizedAmount = Math.floor( new BigNumber(amount).multipliedBy(this.tokenDecimals).toNumber() @@ -152,7 +154,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, options); if (txHash) { return { From 12d5a3d359c30feb2d810a81ff1fa9e4f021125b Mon Sep 17 00:00:00 2001 From: Juan Olmedo Date: Wed, 27 Aug 2025 11:39:51 -0300 Subject: [PATCH 3/3] refactor: remove rest api options param --- packages/dag4-network/src/api/v2/l1-api.ts | 14 +++++++------- packages/dag4-network/src/dag-network.ts | 5 ++--- .../dag4-network/src/metagraph-token-network.ts | 6 ++---- packages/dag4-wallet/src/dag-account.ts | 15 +++++++-------- .../dag4-wallet/src/metagraph-token-client.ts | 15 +++++++-------- packages/dag4-wallet/src/shared/operations.ts | 11 ++++------- 6 files changed, 29 insertions(+), 37 deletions(-) diff --git a/packages/dag4-network/src/api/v2/l1-api.ts b/packages/dag4-network/src/api/v2/l1-api.ts index e9bbe99..3b8cd78 100644 --- a/packages/dag4-network/src/api/v2/l1-api.ts +++ b/packages/dag4-network/src/api/v2/l1-api.ts @@ -1,4 +1,4 @@ -import { RestApi, RestApiOptions } from "@stardust-collective/dag4-core"; +import { RestApi } from "@stardust-collective/dag4-core"; import { DNC } from "../../DNC"; import { ClusterInfoV2, @@ -90,8 +90,8 @@ class L1Api { ); } - async postAllowSpend(signedAllowSpend: SignedAllowSpend, params?: Record, options?: RestApiOptions) { - return this.service.$post(`/allow-spends`, signedAllowSpend, options, params); + 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, params?: Record, options?: RestApiOptions) { - return this.service.$post(`/token-locks`, signedTokenLock, options, params); + 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, params?: Record, options?: RestApiOptions) { - return this.service.$post("/transactions", tx, options, params); + 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 ef54125..e37340f 100644 --- a/packages/dag4-network/src/dag-network.ts +++ b/packages/dag4-network/src/dag-network.ts @@ -7,7 +7,6 @@ import { L1Api } from './api/v2/l1-api'; import { CbTransaction, PostTransaction, Snapshot, Transaction } from './dto/v1'; import { PendingTransaction, PostTransactionV2, SnapshotV2, TransactionV2 } from './dto/v2'; import { NetworkInfo } from './types/network-info'; -import { RestApiOptions } from '@stardust-collective/dag4-core'; export class DagNetwork { private connectedNetwork: NetworkInfo = { @@ -125,9 +124,9 @@ export class DagNetwork { return this.blockExplorerApi.getTransaction(hash); } - async postTransaction(tx: PostTransaction | PostTransactionV2, params?: Record, options?: RestApiOptions): Promise { + async postTransaction(tx: PostTransaction | PostTransactionV2, params?: Record): Promise { if (this.getNetworkVersion() === '2.0') { - const response = await this.l1Api.postTransaction(tx as PostTransactionV2, params, options) 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 2123216..04f396f 100644 --- a/packages/dag4-network/src/metagraph-token-network.ts +++ b/packages/dag4-network/src/metagraph-token-network.ts @@ -1,4 +1,3 @@ -import { RestApiOptions } from "@stardust-collective/dag4-core"; import { MetagraphTokenDataL1Api } from "./api/metagraph-token/data-l1-api"; import { MetagraphTokenL0Api } from "./api/metagraph-token/l0-api"; import { MetagraphTokenL1Api } from "./api/metagraph-token/l1-api"; @@ -151,11 +150,10 @@ class MetagraphTokenNetwork { return response ? response.data : null; } - async postTransaction(tx: PostTransactionV2, params?: Record, options?: RestApiOptions): Promise { + async postTransaction(tx: PostTransactionV2, params?: Record): Promise { const response = (await this.l1Api.postTransaction( tx as PostTransactionV2, - params, - options + 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 90bd6ca..3332747 100644 --- a/packages/dag4-wallet/src/dag-account.ts +++ b/packages/dag4-wallet/src/dag-account.ts @@ -1,4 +1,4 @@ -import { DAG_DECIMALS, RestApiOptions } from "@stardust-collective/dag4-core"; +import { DAG_DECIMALS } from "@stardust-collective/dag4-core"; import { keyStore, KeyTrio, @@ -359,8 +359,7 @@ export class DagAccount { amount: number, fee = 0, autoEstimateFee = false, - params?: Record, - options?: RestApiOptions + params?: Record ): Promise { let normalizedAmount = Math.floor( new BigNumber(amount).multipliedBy(DAG_DECIMALS).toNumber() @@ -387,7 +386,7 @@ export class DagAccount { } const tx = await this.generateSignedTransaction(toAddress, amount, fee); - const txHash = await this.network.postTransaction(tx, params, options); + const txHash = await this.network.postTransaction(tx, params); if (txHash) { return { @@ -635,7 +634,7 @@ export class DagAccount { return allowSpendResponse; } - async createAllowSpend(body: AllowSpend, params?: Record, options?: RestApiOptions) { + async createAllowSpend(body: AllowSpend, params?: Record) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -648,7 +647,7 @@ export class DagAccount { currencyId: null, }; - return allowSpend(bodyWithCurrencyId, this.network, this.keyTrio, params, options); + return allowSpend(bodyWithCurrencyId, this.network, this.keyTrio, params); } /** @@ -737,7 +736,7 @@ export class DagAccount { return tokenLockResponse; } - async createTokenLock(body: TokenLock, params?: Record, options?: RestApiOptions) { + async createTokenLock(body: TokenLock, params?: Record) { this.assertAccountIsActive(); this.assertValidPrivateKey(); @@ -750,7 +749,7 @@ export class DagAccount { currencyId: null, }; - return tokenLock(bodyWithCurrencyId, this.network, this.keyTrio, params, options); + 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 7261809..813580a 100644 --- a/packages/dag4-wallet/src/metagraph-token-client.ts +++ b/packages/dag4-wallet/src/metagraph-token-client.ts @@ -1,4 +1,4 @@ -import { DAG_DECIMALS, RestApiOptions } from "@stardust-collective/dag4-core"; +import { DAG_DECIMALS } from "@stardust-collective/dag4-core"; import { PostTransactionV2 } from "@stardust-collective/dag4-keystore"; import { ActionType, @@ -116,8 +116,7 @@ class MetagraphTokenClient { amount: number, fee = 0, autoEstimateFee = false, - params?: Record, - options?: RestApiOptions + params?: Record ): Promise { let normalizedAmount = Math.floor( new BigNumber(amount).multipliedBy(this.tokenDecimals).toNumber() @@ -154,7 +153,7 @@ class MetagraphTokenClient { throw new Error("Unable to post v1 transaction"); } - const txHash = await this.network.postTransaction(tx, params, options); + const txHash = await this.network.postTransaction(tx, params); if (txHash) { return { @@ -251,7 +250,7 @@ class MetagraphTokenClient { return this.sendBatchTransactions(txns); } - async createAllowSpend(body: AllowSpend, params?: Record, options?: RestApiOptions) { + async createAllowSpend(body: AllowSpend, params?: Record) { this.account.assertAccountIsActive(); this.account.assertValidPrivateKey(); @@ -264,10 +263,10 @@ class MetagraphTokenClient { currencyId: this.networkInfo.metagraphId, }; - return allowSpend(bodyWithCurrencyId, this.network, this.account.keyTrio, params, options); + return allowSpend(bodyWithCurrencyId, this.network, this.account.keyTrio, params); } - async createTokenLock(body: TokenLock, params?: Record, options?: RestApiOptions) { + async createTokenLock(body: TokenLock, params?: Record) { this.account.assertAccountIsActive(); this.account.assertValidPrivateKey(); @@ -280,7 +279,7 @@ class MetagraphTokenClient { currencyId: this.networkInfo.metagraphId, }; - return tokenLock(bodyWithCurrencyId, this.network, this.account.keyTrio, params, options); + 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 c24a345..4beefc2 100644 --- a/packages/dag4-wallet/src/shared/operations.ts +++ b/packages/dag4-wallet/src/shared/operations.ts @@ -19,7 +19,6 @@ import { validateArraySchema, validateSchema, } from "../validationSchemas"; -import { RestApiOptions } from "@stardust-collective/dag4-core"; type SharedNetwork = DagNetwork | GlobalDagNetwork | MetagraphTokenNetwork; @@ -27,8 +26,7 @@ export const allowSpend = async ( body: AllowSpendWithCurrencyId, network: SharedNetwork, keyTrio: KeyTrio, - params?: Record, - options?: RestApiOptions + params?: Record ): Promise => { validateSchema(body, allowSpendSchema, true); @@ -85,7 +83,7 @@ export const allowSpend = async ( try { // Post signed allow spend body - allowSpendResponse = await network.l1Api.postAllowSpend(signedAllowSpend, params, options); + allowSpendResponse = await network.l1Api.postAllowSpend(signedAllowSpend, params); } catch (err) { console.error("Error sending the allow spend transaction"); throw err; @@ -102,8 +100,7 @@ export const tokenLock = async ( body: TokenLockWithCurrencyId, network: SharedNetwork, keyTrio: KeyTrio, - params?: Record, - options?: RestApiOptions + params?: Record ): Promise => { validateSchema(body, tokenLockSchema, true); @@ -153,7 +150,7 @@ export const tokenLock = async ( try { // Post signed token lock body - tokenLockResponse = await network.l1Api.postTokenLock(signedTokenLock, params, options); + tokenLockResponse = await network.l1Api.postTokenLock(signedTokenLock, params); } catch (err) { console.error("Error sending the token lock transaction"); throw err;