Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ton-watcher

Package Overview
Dependencies
Maintainers
0
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ton-watcher - npm Package Compare versions

Comparing version 1.1.7 to 1.1.8

build/modules/wallet/CoreV4.d.ts

2

build/modules/process/runProcess.d.ts

@@ -17,2 +17,3 @@ import { STATUS } from "../../modules/txs/sendTx";

req_id: number;
seqno: number;
} | {

@@ -35,2 +36,3 @@ error: string;

req_id: number;
seqno: number;
} | {

@@ -37,0 +39,0 @@ error: string;

42

build/modules/process/runProcess.js

@@ -11,7 +11,6 @@ "use strict";

const safeJson_1 = require("../../utils/safeJson");
const Core_1 = require("../wallet/Core");
const axios_1 = __importDefault(require("axios"));
const axios_request_throttle_1 = __importDefault(require("axios-request-throttle"));
const sendTx_1 = require("../../modules/txs/sendTx");
const tonTxWatcherV4_1 = require("../../modules/txs/tonTxWatcherV4");
const CoreV4_1 = require("modules/wallet/CoreV4");
async function runWatcher(init) {

@@ -27,5 +26,6 @@ if (!init) {

axios_request_throttle_1.default.use(axios_1.default, { requestsPerSecond: isTestnet ? 0.8 : 5 });
const endpoint = isTestnet ? 'https://testnet.toncenter.com/api/v2/jsonRPC' : await (0, ton_access_1.getHttpEndpoint)({ network: init.network });
// const endpoint = isTestnet ? 'https://testnet.toncenter.com/api/v2/jsonRPC' : await getHttpEndpoint({ network: init.network });
const endpoint = await (0, ton_access_1.getHttpV4Endpoint)({ network: init.network });
const endpoint4 = await (0, ton_access_1.getHttpV4Endpoint)({ network: init.network });
const core = await Core_1.TonInteraction.fabric({
const core = await CoreV4_1.TonInteractionV4.fabric({
endpoint,

@@ -39,3 +39,2 @@ key_pair,

});
const txSender = new sendTx_1.SendTx(core);
const txWatcher = new tonTxWatcherV4_1.TonTxWatcherV4(client4, address.toString({ testOnly: isTestnet }), init.last_lt, init.last_hash, undefined, {

@@ -46,2 +45,3 @@ tonBalance: (data) => { process.send && process.send((0, safeJson_1.safeJSONStringify)({ data, event: 'tonBalance' })); },

lastState: (data) => { process.send && process.send((0, safeJson_1.safeJSONStringify)({ data, event: 'lastState' })); },
txs: (data) => { process.send && process.send((0, safeJson_1.safeJSONStringify)({ data, event: 'txs' })); },
logger: (level, data) => { process.send && process.send((0, safeJson_1.safeJSONStringify)({ data: { level, data: data }, event: 'logger' })); },

@@ -51,3 +51,3 @@ }, init.jettons_config, isTestnet);

process.send && process.send(`{ "event": "address", "data": { "address" : "${address.toString()}" }}`);
process.on('message', (data) => executeCommand(core, txSender, data));
process.on('message', (data) => executeCommand(core, data));
}

@@ -61,3 +61,3 @@ catch (e) {

}
function executeCommand(ton, txSender, data) {
function executeCommand(ton, data) {
try {

@@ -71,5 +71,5 @@ const event = JSON.parse(data);

case 'reqSendJetton':
return sendJetton(event, ton, txSender);
return sendJetton(event, ton);
case 'reqSendTon':
return sendTon(event, ton, txSender);
return sendTon(event, ton);
}

@@ -81,3 +81,3 @@ }

}
async function sendTon(event, ton, sendTx) {
async function sendTon(event, ton) {
const { amount, destination, message, req_id } = event.data;

@@ -103,6 +103,6 @@ try {

const transfer = await ton.transferTonMessage(destination, amount_bigint * BigInt(10 ** 9), message);
const res = await sendTx.sendMessage(transfer.message);
if (res.tx) { // TODO check fail tx and send error on fail
try {
const res = await ton.sendTx(transfer.message);
const event = {
data: { req_id, hash: res.txhash, lt: res.tx.lt.toString(), msgHash: res.message_hash, status: res.status, reason: null },
data: { req_id, hash: null, lt: null, msgHash: res.messageHash, status: 'ok', reason: null, seqno: transfer.seqno },
event: "resSendTon"

@@ -112,5 +112,5 @@ };

}
else {
catch (e) {
const event = {
data: { req_id, hash: res.txhash, lt: null, msgHash: res.message_hash, status: res.status, reason: null },
data: { req_id, hash: null, lt: null, msgHash: transfer.messageHash, status: 'ok', reason: null, seqno: transfer.seqno },
event: "resSendTon"

@@ -129,3 +129,3 @@ };

}
async function sendJetton(event, ton, sendTx) {
async function sendJetton(event, ton) {
const { amount, destination, message, req_id, name } = event.data;

@@ -161,6 +161,6 @@ try {

const transfer = await ton.transferJettonMessage(destination, jetton_settings.jettonMasterAddress.toString(), amount_bigint * BigInt(10 ** jetton_settings.decimals), message);
const res = await sendTx.sendMessage(transfer.message);
if (res.tx) { // TODO check fail tx and send error on fail
try {
const res = await ton.sendTx(transfer.message);
const event = {
data: { req_id, hash: res.txhash, lt: res.tx.lt.toString(), msgHash: res.message_hash, status: res.status, reason: null },
data: { req_id, hash: null, lt: null, msgHash: res.messageHash, status: 'ok', reason: null, seqno: transfer.seqno },
event: "resSendJetton"

@@ -170,5 +170,5 @@ };

}
else {
catch (e) {
const event = {
data: { req_id, hash: res.txhash, lt: null, msgHash: res.message_hash, status: res.status, reason: null },
data: { req_id, hash: null, lt: null, msgHash: transfer.messageHash, status: 'ok', reason: null, seqno: transfer.seqno },
event: "resSendJetton"

@@ -175,0 +175,0 @@ };

@@ -35,3 +35,3 @@ import { TonClient4, Transaction } from "@ton/ton";

}) => void | Promise<void>;
transferTx?: (data?: any) => void | Promise<void>;
txs?: (data?: any) => void | Promise<void>;
lastState?: (data: {

@@ -38,0 +38,0 @@ lt: string;

@@ -115,2 +115,3 @@ "use strict";

const parsed_tx = (0, Transaction_1.parse_tx)(tx, this.is_testnet);
this.processing_out_tx(parsed_tx);
if (parsed_tx.inMessage.jetton_notify) {

@@ -140,7 +141,2 @@ const source = parsed_tx.inMessage.sender;

}
else if (parsed_tx.inMessage.type === 'external-in' || parsed_tx.inMessage.recipient === this.address.toString()) {
this.processing_out_tx(parsed_tx);
}
else {
}
}

@@ -208,3 +204,3 @@ onLastState(lastTransaction) {

processing_out_tx(data) {
this.callbacks?.transferTx && this.callbacks.transferTx(data);
this.callbacks?.txs && this.callbacks.txs(data);
}

@@ -211,0 +207,0 @@ updateTonBalance(balance) {

{
"name": "ton-watcher",
"version": "1.1.7",
"version": "1.1.8",
"description": "",

@@ -5,0 +5,0 @@ "main": "build/index.js",

@@ -1,2 +0,2 @@

import { getHttpEndpoint, getHttpV4Endpoint } from "@orbs-network/ton-access";
import { getHttpV4Endpoint } from "@orbs-network/ton-access";
import { Address, TonClient4, WalletContractV5R1 } from "@ton/ton";

@@ -10,9 +10,10 @@ import { keyPairFromSecretKey } from "@ton/crypto";

import { TonTxWatcherV4 } from "../../modules/txs/tonTxWatcherV4";
import { TonInteractionV4 } from "modules/wallet/CoreV4";
type Events = {
reqSendJetton: { destination: string, name: string, amount: string, message: string, req_id: number };
resSendJetton: { hash: string | null, lt: string | null, msgHash: string | null, status: typeof STATUS[keyof typeof STATUS], reason: string | null, req_id: number } | { error: string, req_id: number };
resSendJetton: { hash: string | null, lt: string | null, msgHash: string | null, status: typeof STATUS[keyof typeof STATUS], reason: string | null, req_id: number, seqno: number } | { error: string, req_id: number };
reqSendTon: { destination: string, amount: string, message: string, req_id: number };
resSendTon: { hash: string | null, lt: string | null, msgHash: string | null, status: typeof STATUS[keyof typeof STATUS], reason: string | null, req_id: number } | { error: string, req_id: number };
resSendTon: { hash: string | null, lt: string | null, msgHash: string | null, status: typeof STATUS[keyof typeof STATUS], reason: string | null, req_id: number, seqno: number } | { error: string, req_id: number };

@@ -52,7 +53,8 @@ reqTonBalance: { req_id: number; address?: string; };

axiosThrottle.use(axios, { requestsPerSecond: isTestnet ? 0.8 : 5 });
const endpoint = isTestnet ? 'https://testnet.toncenter.com/api/v2/jsonRPC' : await getHttpEndpoint({ network: init.network });
// const endpoint = isTestnet ? 'https://testnet.toncenter.com/api/v2/jsonRPC' : await getHttpEndpoint({ network: init.network });
const endpoint = await getHttpV4Endpoint({ network: init.network });
const endpoint4 = await getHttpV4Endpoint({ network: init.network });
const core = await TonInteraction.fabric({
const core = await TonInteractionV4.fabric({
endpoint,

@@ -68,9 +70,8 @@ key_pair,

const txSender = new SendTx(core);
const txWatcher = new TonTxWatcherV4(client4, address.toString({ testOnly: isTestnet }), init.last_lt, init.last_hash, undefined, {
tonBalance: (data: unknown) => { process.send && process.send(safeJSONStringify({data, event: 'tonBalance'})) },
jettonBalance: (data: unknown) => { process.send && process.send(safeJSONStringify({data, event: 'jettonBalance'})) },
jettonDeposit: (data: unknown) => { process.send && process.send(safeJSONStringify({data, event: 'jettonDeposit'})) },
lastState: (data: unknown) => { process.send && process.send(safeJSONStringify({data, event: 'lastState'})) },
tonBalance: (data: unknown) => { process.send && process.send(safeJSONStringify({ data, event: 'tonBalance'})) },
jettonBalance: (data: unknown) => { process.send && process.send(safeJSONStringify({ data, event: 'jettonBalance'})) },
jettonDeposit: (data: unknown) => { process.send && process.send(safeJSONStringify({ data, event: 'jettonDeposit'})) },
lastState: (data: unknown) => { process.send && process.send(safeJSONStringify({ data, event: 'lastState'})) },
txs: (data: unknown) => { process.send && process.send(safeJSONStringify({ data, event: 'txs'})) },
logger: (level: 'error' | 'info' | 'warning' | 'debug', data: unknown) => { process.send && process.send(safeJSONStringify({data: { level, data: data }, event: 'logger'}))},

@@ -81,3 +82,3 @@ }, init.jettons_config, isTestnet);

process.send && process.send(`{ "event": "address", "data": { "address" : "${address.toString()}" }}`);
process.on('message', (data: string) => executeCommand(core, txSender, data));
process.on('message', (data: string) => executeCommand(core, data));
} catch(e) {

@@ -92,3 +93,3 @@ process.send && process.send(safeJSONStringify({ event: 'error', data: e }));

function executeCommand(ton: TonInteraction, txSender: SendTx, data: string) {
function executeCommand(ton: TonInteractionV4, data: string) {
try {

@@ -102,5 +103,5 @@ const event: TonProcessEvents = JSON.parse(data);

case 'reqSendJetton':
return sendJetton(event, ton, txSender);
return sendJetton(event, ton);
case 'reqSendTon':
return sendTon(event, ton, txSender);
return sendTon(event, ton);

@@ -114,3 +115,3 @@ }

async function sendTon(event: TonProcessEvents<'reqSendTon'>, ton: TonInteraction, sendTx: SendTx) {
async function sendTon(event: TonProcessEvents<'reqSendTon'>, ton: TonInteractionV4) {
const { amount, destination, message, req_id } = event.data;

@@ -140,19 +141,12 @@

const transfer = await ton.transferTonMessage(destination, amount_bigint * BigInt(10 ** 9), message);
const res = await sendTx.sendMessage(transfer.message);
if (res.tx) { // TODO check fail tx and send error on fail
const event: TonProcessEvents<'resSendTon'> = {
data: { req_id, hash: res.txhash, lt: res.tx.lt.toString(), msgHash: res.message_hash, status: res.status, reason: null },
event: "resSendTon"
};
process.send && process.send(safeJSONStringify(event));
} else {
const event: TonProcessEvents<'resSendTon'> = {
data: { req_id, hash: res.txhash, lt: null, msgHash: res.message_hash, status: res.status, reason: null },
event: "resSendTon"
};
process.send && process.send(safeJSONStringify(event));
}
try {
const res = await ton.sendTx(transfer.message);
const event: TonProcessEvents<'resSendTon'> = {
data: { req_id, hash: null, lt: null, msgHash: res.messageHash, status: 'ok', reason: null, seqno: transfer.seqno },
event: "resSendTon"
};
process.send && process.send(safeJSONStringify(event));
} catch (e) {
const event: TonProcessEvents<'resSendTon'> = {
data: { error: safeJSONStringify(e), req_id },
data: { req_id, hash: null, lt: null, msgHash: transfer.messageHash, status: 'ok', reason: null, seqno: transfer.seqno },
event: "resSendTon"

@@ -162,5 +156,12 @@ };

}
} catch (e) {
const event: TonProcessEvents<'resSendTon'> = {
data: { error: safeJSONStringify(e), req_id },
event: "resSendTon"
};
process.send && process.send(safeJSONStringify(event));
}
}
async function sendJetton(event: TonProcessEvents<'reqSendJetton'>, ton: TonInteraction, sendTx: SendTx) {
async function sendJetton(event: TonProcessEvents<'reqSendJetton'>, ton: TonInteractionV4) {
const { amount, destination, message, req_id, name } = event.data;

@@ -202,12 +203,12 @@

const transfer = await ton.transferJettonMessage(destination, jetton_settings.jettonMasterAddress.toString(), amount_bigint * BigInt(10 ** jetton_settings.decimals), message);
const res = await sendTx.sendMessage(transfer.message);
if (res.tx) { // TODO check fail tx and send error on fail
try {
const res = await ton.sendTx(transfer.message);
const event: TonProcessEvents<'resSendJetton'> = {
data: { req_id, hash: res.txhash, lt: res.tx.lt.toString(), msgHash: res.message_hash, status: res.status, reason: null },
data: { req_id, hash: null, lt: null, msgHash: res.messageHash, status: 'ok', reason: null, seqno: transfer.seqno },
event: "resSendJetton"
};
process.send && process.send(safeJSONStringify(event));
} else {
} catch (e) {
const event: TonProcessEvents<'resSendJetton'> = {
data: { req_id, hash: res.txhash, lt: null, msgHash: res.message_hash, status: res.status, reason: null },
data: { req_id, hash: null, lt: null, msgHash: transfer.messageHash, status: 'ok', reason: null, seqno: transfer.seqno },
event: "resSendJetton"

@@ -226,3 +227,3 @@ };

async function tonBalance(event: TonProcessEvents<'reqTonBalance'>, ton: TonInteraction) {
async function tonBalance(event: TonProcessEvents<'reqTonBalance'>, ton: TonInteractionV4) {
const { req_id, address } = event.data;

@@ -255,3 +256,3 @@ try {

async function jetonBalance(event: TonProcessEvents<'reqJTonBalance'>, ton: TonInteraction) {
async function jetonBalance(event: TonProcessEvents<'reqJTonBalance'>, ton: TonInteractionV4) {
const { jetton_name, req_id, address } = event.data;

@@ -258,0 +259,0 @@ try {

@@ -12,3 +12,3 @@ import { Address, TonClient4, Transaction, WalletContractV5R1 } from "@ton/ton";

tonDeposit?: (data: { address: string, amount: string, message: string, decimals: number, hash: string }) => void | Promise<void>;
transferTx?: (data?: any) => void | Promise<void>;
txs?: (data?: any) => void | Promise<void>;
lastState?: (data: { lt: string, hash: string }) => void | Promise<void>;

@@ -152,2 +152,4 @@ logger?: (level: 'error' | 'info' | 'warning'| 'debug', data: unknown) => void | Promise<void>;

this.processing_out_tx(parsed_tx);
if (parsed_tx.inMessage.jetton_notify) {

@@ -175,6 +177,2 @@ const source = parsed_tx.inMessage.sender as string;

};
} else if (parsed_tx.inMessage.type === 'external-in' || parsed_tx.inMessage.recipient === this.address.toString()) {
this.processing_out_tx(parsed_tx);
} else {
}

@@ -258,3 +256,3 @@ }

private processing_out_tx(data: any) {
this.callbacks?.transferTx && this.callbacks.transferTx(data);
this.callbacks?.txs && this.callbacks.txs(data);
}

@@ -261,0 +259,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc