Skip to content

Commit

Permalink
Merge pull request #15 from krigga/locate-tx
Browse files Browse the repository at this point in the history
Add locate tx methods in api v2
  • Loading branch information
Dan Volkov authored Feb 1, 2024
2 parents b4cbd9d + c2604e2 commit 0a3a1c4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/client/TonClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@ describeConditional('TonClient', () => {

console.log(info, shardInfo, wcShards);
});

it('should locate source/result tx', async () => {
let source = Address.parse('UQDDT0TOC4PMp894jtCo3-d1-8ltSjXMX2EuWww_pCNibsUH');
let createdLt = '37508996000002';

let infoSource = await client.tryLocateSourceTx(source, testAddress, createdLt);
console.log(infoSource);

let infoResult = await client.tryLocateResultTx(source, testAddress, createdLt);
console.log(infoResult);
});
});
24 changes: 24 additions & 0 deletions src/client/TonClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@ export class TonClient {
}
}

/**
* Locate outcoming transaction of destination address by incoming message
* @param source message source address
* @param destination message destination address
* @param created_lt message's created lt
* @returns transaction
*/
async tryLocateResultTx(source: Address, destination: Address, created_lt: string) {
let res = await this.#api.tryLocateResultTx(source, destination, created_lt);
return loadTransaction(Cell.fromBase64(res.data).beginParse());
}

/**
* Locate incoming transaction of source address by outcoming message
* @param source message source address
* @param destination message destination address
* @param created_lt message's created lt
* @returns transaction
*/
async tryLocateSourceTx(source: Address, destination: Address, created_lt: string) {
let res = await this.#api.tryLocateSourceTx(source, destination, created_lt);
return loadTransaction(Cell.fromBase64(res.data).beginParse());
}

/**
* Fetch latest masterchain info
* @returns masterchain info
Expand Down
8 changes: 8 additions & 0 deletions src/client/api/HttpApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,14 @@ export class HttpApi {
}, feeResponse);
}

async tryLocateResultTx(source: Address, destination: Address, created_lt: string) {
return await this.doCall('tryLocateResultTx', { source: source.toString(), destination: destination.toString(), created_lt }, transaction);
}

async tryLocateSourceTx(source: Address, destination: Address, created_lt: string) {
return await this.doCall('tryLocateSourceTx', { source: source.toString(), destination: destination.toString(), created_lt }, transaction);
}

private async doCall<T>(method: string, body: any, codec: z.ZodType<T>) {
let headers: Record<string, any> = {
'Content-Type': 'application/json',
Expand Down

0 comments on commit 0a3a1c4

Please sign in to comment.