Comparing version 4.2.0 to 4.3.0
@@ -12,2 +12,35 @@ /// <reference types="node" /> | ||
}>; | ||
getTransactions(address: Address, opts: { | ||
limit: number; | ||
lt?: string; | ||
hash?: string; | ||
to_lt?: string; | ||
}): Promise<{ | ||
data: string; | ||
transaction_id: { | ||
lt: string; | ||
hash: string; | ||
}; | ||
fee: string; | ||
storage_fee: string; | ||
other_fee: string; | ||
in_msg: { | ||
source: string; | ||
destination: string; | ||
value: string; | ||
fwd_fee: string; | ||
ihr_fee: string; | ||
created_lt: string; | ||
body_hash: string; | ||
}; | ||
out_msgs: { | ||
source: string; | ||
destination: string; | ||
value: string; | ||
fwd_fee: string; | ||
ihr_fee: string; | ||
created_lt: string; | ||
body_hash: string; | ||
}[]; | ||
}[]>; | ||
callGetMethod(address: Address, method: string, params: any[]): Promise<{ | ||
@@ -14,0 +47,0 @@ gas_used: number; |
@@ -44,2 +44,30 @@ "use strict"; | ||
}); | ||
const getTransactions = t.array(t.type({ | ||
data: t.string, | ||
transaction_id: t.type({ | ||
lt: t.string, | ||
hash: t.string | ||
}), | ||
fee: t.string, | ||
storage_fee: t.string, | ||
other_fee: t.string, | ||
in_msg: t.type({ | ||
source: t.string, | ||
destination: t.string, | ||
value: t.string, | ||
fwd_fee: t.string, | ||
ihr_fee: t.string, | ||
created_lt: t.string, | ||
body_hash: t.string | ||
}), | ||
out_msgs: t.array(t.type({ | ||
source: t.string, | ||
destination: t.string, | ||
value: t.string, | ||
fwd_fee: t.string, | ||
ihr_fee: t.string, | ||
created_lt: t.string, | ||
body_hash: t.string | ||
})) | ||
})); | ||
class HttpApi { | ||
@@ -53,2 +81,5 @@ endpoint; | ||
} | ||
async getTransactions(address, opts) { | ||
return await this.doCall('getTransactions', { address: address.toString(), ...opts }, getTransactions); | ||
} | ||
async callGetMethod(address, method, params) { | ||
@@ -55,0 +86,0 @@ return await this.doCall('runGetMethod', { address: address.toString(), method, stack: params }, callGetMethod); |
@@ -14,3 +14,3 @@ "use strict"; | ||
}); | ||
it('should get latest transactions', async () => { | ||
it('should send external messages', async () => { | ||
const api = new HttpApi_1.HttpApi('https://testnet.toncenter.com/api/v2/jsonRPC'); | ||
@@ -30,2 +30,6 @@ const message = new ExternalMessage_1.ExternalMessage({ | ||
}); | ||
it('should get transactions', async () => { | ||
const api = new HttpApi_1.HttpApi('https://toncenter.com/api/v2/jsonRPC'); | ||
await api.getTransactions(__1.Address.parseFriendly('kf91o4NNTryJ-Cw3sDGt9OTiafmETdVFUMvylQdFPoOxIsLm').address, { limit: 10 }); | ||
}); | ||
}); |
@@ -39,2 +39,12 @@ /// <reference types="bn.js" /> | ||
/** | ||
* Get transactions | ||
* @param address address | ||
*/ | ||
getTransactions(address: Address, opts: { | ||
limit: number; | ||
lt?: string; | ||
hash?: string; | ||
to_lt?: string; | ||
}): Promise<void>; | ||
/** | ||
* Send message to a network | ||
@@ -41,0 +51,0 @@ * @param src source message |
@@ -5,2 +5,3 @@ "use strict"; | ||
const ton_crypto_1 = require("ton-crypto"); | ||
const Address_1 = require("../address/Address"); | ||
const Cell_1 = require("../boc/Cell"); | ||
@@ -48,2 +49,32 @@ const HttpApi_1 = require("./api/HttpApi"); | ||
/** | ||
* Get transactions | ||
* @param address address | ||
*/ | ||
async getTransactions(address, opts) { | ||
// Fetch transactions | ||
let tx = await this.#api.getTransactions(address, opts); | ||
let res = []; | ||
function convertMessage(t) { | ||
return { | ||
source: t.source !== '' ? Address_1.Address.parseFriendly(t.source).address : null, | ||
destination: t.destination !== '' ? Address_1.Address.parseFriendly(t.destination).address : null, | ||
forwardFee: new bn_js_1.BN(t.fwd_fee), | ||
ihrFee: new bn_js_1.BN(t.ihr_fee), | ||
value: new bn_js_1.BN(t.value), | ||
createdLt: t.created_lt | ||
}; | ||
} | ||
for (let r of tx) { | ||
res.push({ | ||
id: { lt: r.transaction_id.lt, hash: r.transaction_id.hash }, | ||
data: r.data, | ||
storageFee: new bn_js_1.BN(r.storage_fee), | ||
otherFee: new bn_js_1.BN(r.other_fee), | ||
fee: new bn_js_1.BN(r.fee), | ||
inMessage: convertMessage(r.in_msg), | ||
outMessages: r.out_msgs.map(convertMessage) | ||
}); | ||
} | ||
} | ||
/** | ||
* Send message to a network | ||
@@ -50,0 +81,0 @@ * @param src source message |
import BN from "bn.js"; | ||
import { Address } from ".."; | ||
export declare type TonMessage = { | ||
source: string | null; | ||
destination: string | null; | ||
source: Address | null; | ||
destination: Address | null; | ||
value: BN; | ||
@@ -9,3 +10,2 @@ forwardFee: BN; | ||
createdLt: string; | ||
message: string | null; | ||
}; | ||
@@ -12,0 +12,0 @@ export declare type TonTransaction = { |
@@ -8,1 +8,2 @@ export { BitString } from './boc/BitString'; | ||
export { KeyStore, KeyRecord } from './keystore/KeyStore'; | ||
export { TonTransaction, TonMessage } from './client/TonTransaction'; |
{ | ||
"name": "ton", | ||
"version": "4.2.0", | ||
"version": "4.3.0", | ||
"repository": "https://github.com/ex3ndr/ton.git", | ||
@@ -5,0 +5,0 @@ "author": "Steve Korshakov <steve@korshakov.com>", |
161911
4249