Skip to content

Commit

Permalink
update v2 getTransactions && subscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
ndatg committed Apr 26, 2024
1 parent 7f8b0be commit c33a5ff
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion examples/subscriberV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const main = async () => {
});

const storage = new TonMemoryBlockStorageV2();
// const storage = new TonRedisBlockStorage("redis://:[email protected]:6379/0");
// const storage = new TonRedisBlockStorageV2("redis://:[email protected]:6379/0");

const logger = Logger({
transport: {
Expand Down
5 changes: 3 additions & 2 deletions examples/subscriberV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import {
TonHttpApiV3,
TonSubscriberV3,
TonMemoryBlockStorageV3,
TonRedisBlockStorageV3,
SchemaV3
} from "../src";
import Logger from "pino";

const main = async () => {
const api = new TonHttpApiV3({
endpoint: "https://stage.toncenter.com/",
endpoint: "https://toncenter.com/",
apiKey: ""
});

const storage = new TonMemoryBlockStorageV3();
// const storage = new TonRedisBlockStorage("redis://:[email protected]:6379/0");
// const storage = new TonRedisBlockStorageV3("redis://:[email protected]:6379/0");

const logger = Logger({
transport: {
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ton-http-api",
"version": "2.0.5",
"version": "2.0.6",
"description": "The lightweight TON Typescript Library",
"main": "dist/index.js",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/TonHttpApiV2/SchemaV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export const message = z.object({
created_lt: z.string(),
body_hash: z.string(),
msg_data: messageData,
message: z.string()
message: z.string().optional()
});
export type Message = z.infer<typeof message>;

Expand Down
22 changes: 11 additions & 11 deletions src/TonSubscriberV2/TonRedisBlockStorageV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export class TonRedisBlockStorageV2 implements TonBlockStorageV2 {
continue;
}

if (await this.#redis.hexists("shardchainBlocks", `${workchain}_${shard}_${seqno}`)) {
if (await this.#redis.hexists("ton:shardchain_blocks", `${workchain}_${shard}_${seqno}`)) {
continue;
}

await this.#redis.hset("shardchainBlocks", {
await this.#redis.hset("ton:shardchain_blocks", {
[`${workchain}_${shard}_${seqno}`]: 0
});
}
Expand All @@ -35,10 +35,10 @@ export class TonRedisBlockStorageV2 implements TonBlockStorageV2 {
* @param seqno
*/
async insertMasterchainBlock(seqno: number) {
if (await this.#redis.hexists("masterchainBlocks", `${seqno}`)) {
if (await this.#redis.hexists("ton:masterchain_blocks", `${seqno}`)) {
throw Error(`masterchain block already exists! seqno: ${seqno}`);
}
await this.#redis.hset("masterchainBlocks", {
await this.#redis.hset("ton:masterchain_blocks", {
[seqno]: 1
});
}
Expand All @@ -47,7 +47,7 @@ export class TonRedisBlockStorageV2 implements TonBlockStorageV2 {
* Get the last inserted masterchain block from the masterchain hashtable.
*/
async getLastMasterchainBlock() {
const masterchainBlocks = await this.#redis.hgetall("masterchainBlocks");
const masterchainBlocks = await this.#redis.hgetall("ton:masterchain_blocks");
const data = Object.keys(masterchainBlocks)
.map(x => Number(x))
.sort((a, b) => b - a);
Expand All @@ -58,8 +58,8 @@ export class TonRedisBlockStorageV2 implements TonBlockStorageV2 {
* Get the last unprocessed shardchain block from the shardchains hashtable.
*/
async getUnprocessedShardchainBlock() {
const shardchainBlocks = await this.#redis.hgetall("shardchainBlocks");
console.log(shardchainBlocks);
const shardchainBlocks = await this.#redis.hgetall("ton:shardchain_blocks");
// console.log(shardchainBlocks);
for (const key in shardchainBlocks) {
if (shardchainBlocks[key] !== undefined && !parseInt(shardchainBlocks[key])) {
const data = key.split("_");
Expand All @@ -82,13 +82,13 @@ export class TonRedisBlockStorageV2 implements TonBlockStorageV2 {
* @param prevShardBlocks
*/
async setShardchainBlockProcessed(workchain: number, shard: string, seqno: number, prevShardBlocks: BlockIdExt[]) {
if (!await this.#redis.hexists("shardchainBlocks", `${workchain}_${shard}_${seqno}`)) {
if (!await this.#redis.hexists("ton:shardchain_blocks", `${workchain}_${shard}_${seqno}`)) {
throw Error(
`shardchain not found! workchain: ${workchain} / shard: ${shard} / seqno: ${seqno}`
);
}

await this.#redis.hset("shardchainBlocks", {
await this.#redis.hset("ton:shardchain_blocks", {
[`${workchain}_${shard}_${seqno}`]: 1
});
await this.insertShardchainBlocks(prevShardBlocks);
Expand All @@ -98,7 +98,7 @@ export class TonRedisBlockStorageV2 implements TonBlockStorageV2 {
* Clean up the hashtables.
*/
async clean() {
await this.#redis.del("masterchainBlocks");
await this.#redis.del("shardchainBlocks");
await this.#redis.del("ton:masterchain_blocks");
await this.#redis.del("ton:shardchain_blocks");
}
}
8 changes: 4 additions & 4 deletions src/TonSubscriberV3/TonRedisBlockStorageV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export class TonRedisBlockStorageV3 implements TonBlockStorageV3 {
* @param seqno
*/
async insertMasterchainBlock(seqno: number) {
if (await this.#redis.hexists("masterchainBlocks", `${seqno}`)) {
if (await this.#redis.hexists("ton:masterchain_blocks", `${seqno}`)) {
throw Error(`masterchain block already exists! seqno: ${seqno}`);
}
await this.#redis.hset("masterchainBlocks", {
await this.#redis.hset("ton:masterchain_blocks", {
[seqno]: 1
});
}
Expand All @@ -26,7 +26,7 @@ export class TonRedisBlockStorageV3 implements TonBlockStorageV3 {
* Get the last inserted masterchain block from the masterchain hashtable.
*/
async getLastMasterchainBlock() {
const masterchainBlocks = await this.#redis.hgetall("masterchainBlocks");
const masterchainBlocks = await this.#redis.hgetall("ton:masterchain_blocks");
const data = Object.keys(masterchainBlocks)
.map(x => Number(x))
.sort((a, b) => b - a);
Expand All @@ -37,6 +37,6 @@ export class TonRedisBlockStorageV3 implements TonBlockStorageV3 {
* Clean up the hashtable.
*/
async clean() {
await this.#redis.del("masterchainBlocks");
await this.#redis.del("ton:masterchain_blocks");
}
}

0 comments on commit c33a5ff

Please sign in to comment.