Skip to content

Commit

Permalink
Refactor wallets to push message, do not use ls if not configured
Browse files Browse the repository at this point in the history
  • Loading branch information
TrueCarry committed Feb 2, 2024
1 parent 14bc143 commit 9800cef
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 47 deletions.
19 changes: 18 additions & 1 deletion client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { TonClient, TonClient4 } from "@ton/ton"
import axios from "axios"
import { LiteClient, LiteSingleEngine, LiteRoundRobinEngine } from "ton-lite-client"
import { getHttpEndpoint, getHttpV4Endpoint } from "@orbs-network/ton-access";
import { HttpClient, Api } from 'tonapi-sdk-js';

let lc4: TonClient4 | undefined = undefined
let lc: LiteClient | undefined = undefined

let lcOrbs: TonClient4 | undefined = undefined
let lcHub: TonClient4 | undefined = undefined

let lcToncenter: TonClient| undefined = undefined
let lcToncenter: TonClient | undefined = undefined

let createLiteClient: Promise<void>

Expand Down Expand Up @@ -93,4 +94,20 @@ export async function getLiteClient(_configUrl): Promise<LiteClient> {
await createLiteClient

return lc as any
}

export async function getTonapiClient(): Promise<Api<unknown>> {
const httpClient = new HttpClient({
baseUrl: 'https://tonapi.io/',
baseApiParams: {
headers: {
Authorization: `Bearer ${process.env.TONAPI_TOKEN}`,
'Content-type': 'application/json'
}
}
});

// Initialize the API client
const client = new Api(httpClient);
return client
}
6 changes: 6 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"axios": "^1.6.7",
"dotenv": "^16.4.1",
"ton-lite-client": "npm:@truecarry/ton-lite-client@^3.1.1",
"tonapi-sdk-js": "^1.0.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
Expand Down
57 changes: 11 additions & 46 deletions send_universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async function main() {

setInterval(() => {
updateBestGivers(liteClient, wallet.address)
}, 1000)
}, 30000)

while (go) {
const giverAddress = bestGiver.address
Expand Down Expand Up @@ -288,55 +288,20 @@ async function sendMinedBoc(
giverAddress: string,
boc: Cell
) {
const liteServerClient = await getLiteClient(args['-c'] ?? 'https://ton-blockchain.github.io/global.config.json')

const wallets: OpenedContract<WalletContractV4>[] = []
const ton4Client = await getTon4Client()
const tonOrbsClient = await getTon4ClientOrbs()
const toncenterClient = await getTonCenterClient()

const w1 = liteServerClient.open(wallet)
const w2 = ton4Client.open(wallet)
const w3 = tonOrbsClient.open(wallet)
const w4 = toncenterClient.open(wallet)

const wallets = [w1, w2, w3]


// const transferBoc = w1.createTransfer({
// seqno,
// secretKey: keyPair.secretKey,
// messages: [internal({
// to: giverAddress,
// value: toNano('0.05'),
// bounce: true,
// body: boc,
// })],
// sendMode: 3 as any,
// })


// console.log('send seqno', seqno)
// const ext = external({
// to: Address.parse(giverAddress),
// body: transferBoc
// })
// const dataBoc = beginCell().store(storeMessage(ext)).endCell()
// toncenterClient.sendFile(dataBoc.toBoc()).then(() => {
// console.log('toncenter success')
// }).catch(e => {
// //
// console.log('toncenter send error', e)
// })
// w4.sendTransfer({
// seqno,
// secretKey: keyPair.secretKey,
// messages: [internal({
// to: giverAddress,
// value: toNano('0.05'),
// bounce: true,
// body: boc,
// })],
// sendMode: 3 as any,
// })
wallets.push(w2)
wallets.push(w3)

if (args['--api'] === 'lite') {
const liteServerClient = await getLiteClient(args['-c'] ?? 'https://ton-blockchain.github.io/global.config.json')
const w1 = liteServerClient.open(wallet)
wallets.push(w1)
}

for (let i = 0; i < 3; i++) {
for (const w of wallets) {
Expand Down

0 comments on commit 9800cef

Please sign in to comment.