-
Notifications
You must be signed in to change notification settings - Fork 1
/
cosmo.ts
123 lines (119 loc) · 4.07 KB
/
cosmo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import {
DeliverTxResponse,
SigningStargateClient,
StargateClient,
SequenceResponse,
} from "@cosmjs/stargate";
import { CustomSigningStargateClient } from "./cosmo_sequence";
import { Secp256k1HdWallet, Secp256k1Wallet } from "@cosmjs/amino";
import "dotenv/config";
import { encodeAminoPubkey } from "@cosmjs/amino";
import { stringToPath } from "@cosmjs/crypto";
import {
IndexerGrpcAccountPortfolioApi,
InjectiveStargate,
injectiveAccountParser,
} from "@injectivelabs/sdk-ts";
import { InjectiveStargateClient } from "@injectivelabs/sdk-ts/dist/cjs/core/stargate";
import { Tendermint34Client } from "@cosmjs/tendermint-rpc";
import { getNetworkEndpoints, Network } from "@injectivelabs/networks";
const rpc_endpoint = "https://sentry.tm.injective.network:443";
// import{private}
//1 mil denom token = 1 native
let tia_keys = process.env.COSMOS_KEY!.split(",");
const pre_fix_name = "inj";
const token_name = "tia";
const fee = {
amount: [{ denom: "u" + token_name, amount: "400" }],
gas: "95000",
};
const memo =
"ZGF0YToseyJvcCI6Im1pbnQiLCJhbXQiOjEwMDAwLCJ0aWNrIjoiY2lhcyIsInAiOiJjaWEtMjAifQ==";
const value_amount_denom = "1";
const times = 2;
const is_private_key = false;
async function main() {
let seprate_signer_by_wallets: {
client: CustomSigningStargateClient;
address: string;
wallet: Secp256k1HdWallet | Secp256k1Wallet;
sequence: number;
}[] = [];
const network = await (
await StargateClient.connect(rpc_endpoint)
).getChainId();
console.log(network);
for (let key of tia_keys) {
const wallet = is_private_key
? await Secp256k1Wallet.fromKey(Buffer.from(key), pre_fix_name)
: await Secp256k1HdWallet.fromMnemonic(key, {
prefix: pre_fix_name,
});
let address = (await wallet.getAccounts())[0].address;
console.log(address);
const client = await CustomSigningStargateClient.alter_createWithSigner(
rpc_endpoint,
wallet
);
// const inj_endpoint = getNetworkEndpoints(Network.Mainnet);
// const indexerGrpcAccountApi = new IndexerGrpcAccountPortfolioApi(
// inj_endpoint.indexer
// );
const tendermint_client = new Tendermint34Client(rpc_endpoint);
const client_inj = new InjectiveStargateClient(rpc_endpoint);
// let sequence = (await client.getSequence(address)).sequence;
let sequence = await indexerGrpcAccountApi.fetchAccountPortfolio(address);
console.log(sequence);
// seprate_signer_by_wallets.push({ client, address, wallet, sequence });
}
// let counter = 0;
// while (true) {
// let promises: Promise<string | null>[] = [];
// for (let signer of seprate_signer_by_wallets) {
// const msg = {
// typeUrl: "/cosmos.bank.v1beta1.MsgSend",
// value: {
// fromAddress: signer.address,
// toAddress: signer.address,
// amount: [{ denom: "u" + token_name, amount: value_amount_denom }],
// },
// };
// for (let i = 0; i < times; i++) {
// promises.push(
// signer.client
// .signAndBroadcastSyncWithSequence(
// signer.address,
// [msg],
// fee,
// signer.sequence,
// memo
// )
// // signAndBroadcast(signer.address, [msg], fee, memo)
// .catch(async (e) => {
// if (e.message.includes("account sequence mismatch")) {
// signer.sequence = await signer.client
// .getSequence(signer.address)
// .then((res: SequenceResponse) => res.sequence);
// console.log("recatch sequence");
// }
// console.log(e);
// return null;
// })
// );
// signer.sequence++;
// }
// // console.log("pass in");
// }
// console.time();
// await Promise.all(promises).then((array) => {
// for (let i = 0; i < array.length; i++) {
// if (array[i] !== null) {
// counter++;
// console.log("mint:", counter);
// }
// }
// });
// console.timeEnd();
// }
}
main();