Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions packages/dag4-network/src/api/v2/l1-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ class L1Api {
);
}

async postAllowSpend(signedAllowSpend: SignedAllowSpend) {
return this.service.$post<HashResponse>(`/allow-spends`, signedAllowSpend);
async postAllowSpend(signedAllowSpend: SignedAllowSpend, params?: Record<string, any>) {
return this.service.$post<HashResponse>(`/allow-spends`, signedAllowSpend, {}, params);
}

async getTokenLockLastRef(address: string) {
Expand All @@ -100,16 +100,16 @@ class L1Api {
);
}

async postTokenLock(signedTokenLock: SignedTokenLock) {
return this.service.$post<HashResponse>(`/token-locks`, signedTokenLock);
async postTokenLock(signedTokenLock: SignedTokenLock, params?: Record<string, any>) {
return this.service.$post<HashResponse>(`/token-locks`, signedTokenLock, {}, params);
}

async getPendingTransaction(hash: string) {
return this.service.$get<PendingTransaction>(`/transactions/${hash}`);
}

async postTransaction(tx: PostTransactionV2) {
return this.service.$post<PostTransactionResponseV2>("/transactions", tx);
async postTransaction(tx: PostTransactionV2, params?: Record<string, any>) {
return this.service.$post<PostTransactionResponseV2>("/transactions", tx, {}, params);
}

async getClusterInfo(): Promise<ClusterPeerInfoV2[]> {
Expand Down
4 changes: 2 additions & 2 deletions packages/dag4-network/src/dag-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ export class DagNetwork {
return this.blockExplorerApi.getTransaction(hash);
}

async postTransaction(tx: PostTransaction | PostTransactionV2): Promise<string> {
async postTransaction(tx: PostTransaction | PostTransactionV2, params?: Record<string, any>): Promise<string> {
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;
Expand Down
5 changes: 3 additions & 2 deletions packages/dag4-network/src/metagraph-token-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ class MetagraphTokenNetwork {
return response ? response.data : null;
}

async postTransaction(tx: PostTransactionV2): Promise<string> {
async postTransaction(tx: PostTransactionV2, params?: Record<string, any>): Promise<string> {
const response = (await this.l1Api.postTransaction(
tx as PostTransactionV2
tx as PostTransactionV2,
params
)) as any;

// Support data/meta format and object return format
Expand Down
13 changes: 7 additions & 6 deletions packages/dag4-wallet/src/dag-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ export class DagAccount {
toAddress: string,
amount: number,
fee = 0,
autoEstimateFee = false
autoEstimateFee = false,
params?: Record<string, any>
): Promise<PendingTx> {
let normalizedAmount = Math.floor(
new BigNumber(amount).multipliedBy(DAG_DECIMALS).toNumber()
Expand All @@ -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 {
Expand Down Expand Up @@ -633,7 +634,7 @@ export class DagAccount {
return allowSpendResponse;
}

async createAllowSpend(body: AllowSpend) {
async createAllowSpend(body: AllowSpend, params?: Record<string, any>) {
this.assertAccountIsActive();
this.assertValidPrivateKey();

Expand All @@ -646,7 +647,7 @@ export class DagAccount {
currencyId: null,
};

return allowSpend(bodyWithCurrencyId, this.network, this.keyTrio);
return allowSpend(bodyWithCurrencyId, this.network, this.keyTrio, params);
}

/**
Expand Down Expand Up @@ -735,7 +736,7 @@ export class DagAccount {
return tokenLockResponse;
}

async createTokenLock(body: TokenLock) {
async createTokenLock(body: TokenLock, params?: Record<string, any>) {
this.assertAccountIsActive();
this.assertValidPrivateKey();

Expand All @@ -748,7 +749,7 @@ export class DagAccount {
currencyId: null,
};

return tokenLock(bodyWithCurrencyId, this.network, this.keyTrio);
return tokenLock(bodyWithCurrencyId, this.network, this.keyTrio, params);
}

/**
Expand Down
13 changes: 7 additions & 6 deletions packages/dag4-wallet/src/metagraph-token-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ class MetagraphTokenClient {
toAddress: string,
amount: number,
fee = 0,
autoEstimateFee = false
autoEstimateFee = false,
params?: Record<string, any>
): Promise<PendingTx> {
let normalizedAmount = Math.floor(
new BigNumber(amount).multipliedBy(this.tokenDecimals).toNumber()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -249,7 +250,7 @@ class MetagraphTokenClient {
return this.sendBatchTransactions(txns);
}

async createAllowSpend(body: AllowSpend) {
async createAllowSpend(body: AllowSpend, params?: Record<string, any>) {
this.account.assertAccountIsActive();
this.account.assertValidPrivateKey();

Expand All @@ -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<string, any>) {
this.account.assertAccountIsActive();
this.account.assertValidPrivateKey();

Expand All @@ -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) {
Expand Down
10 changes: 6 additions & 4 deletions packages/dag4-wallet/src/shared/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ type SharedNetwork = DagNetwork | GlobalDagNetwork | MetagraphTokenNetwork;
export const allowSpend = async (
body: AllowSpendWithCurrencyId,
network: SharedNetwork,
keyTrio: KeyTrio
keyTrio: KeyTrio,
params?: Record<string, any>
): Promise<HashResponse> => {
validateSchema(body, allowSpendSchema, true);

Expand Down Expand Up @@ -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;
Expand All @@ -98,7 +99,8 @@ export const allowSpend = async (
export const tokenLock = async (
body: TokenLockWithCurrencyId,
network: SharedNetwork,
keyTrio: KeyTrio
keyTrio: KeyTrio,
params?: Record<string, any>
): Promise<HashResponse> => {
validateSchema(body, tokenLockSchema, true);

Expand Down Expand Up @@ -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;
Expand Down