@poolstream/client 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/launch.json +14 -0
- package/LICENSE +121 -0
- package/README.md +157 -0
- package/babel.config.js +6 -0
- package/dist/balance.js +2 -0
- package/dist/balance.js.map +1 -0
- package/dist/currency-network-module.js +23 -0
- package/dist/currency-network-module.js.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/info.js +2 -0
- package/dist/info.js.map +1 -0
- package/dist/network/ripple/ripple.js +50 -0
- package/dist/network/ripple/ripple.js.map +1 -0
- package/dist/network/solana/solana.js +42 -0
- package/dist/network/solana/solana.js.map +1 -0
- package/dist/network/stellar/stellar.js +102 -0
- package/dist/network/stellar/stellar.js.map +1 -0
- package/dist/network/tron/tron.js +63 -0
- package/dist/network/tron/tron.js.map +1 -0
- package/dist/network.js +2 -0
- package/dist/network.js.map +1 -0
- package/dist/poolstream.js +91 -0
- package/dist/poolstream.js.map +1 -0
- package/dist/transaction.js +2 -0
- package/dist/transaction.js.map +1 -0
- package/dist/walletaddress.js +2 -0
- package/dist/walletaddress.js.map +1 -0
- package/logo_up.png +0 -0
- package/package.json +54 -0
- package/src/balance.ts +6 -0
- package/src/currency-network-module.ts +39 -0
- package/src/index.ts +13 -0
- package/src/info.ts +5 -0
- package/src/network/ripple/ripple.ts +66 -0
- package/src/network/solana/solana.ts +73 -0
- package/src/network/stellar/stellar.ts +149 -0
- package/src/network/tron/tron.ts +96 -0
- package/src/network.ts +4 -0
- package/src/poolstream.ts +153 -0
- package/src/transaction.ts +23 -0
- package/src/walletaddress.ts +7 -0
- package/test/network/ripple/ripple.test.ts +31 -0
- package/test/network/solana/solana.test.ts +32 -0
- package/test/network/stellar/stellar.test.ts +56 -0
- package/test/network/tron/tron.test.ts +53 -0
- package/tests.js +13 -0
- package/tsconfig.json +24 -0
@@ -0,0 +1,153 @@
|
|
1
|
+
import { Balance } from "./balance";
|
2
|
+
import { Network } from "./network";
|
3
|
+
import { getCoinNetworkModule } from "./currency-network-module";
|
4
|
+
import { SignebleTransaction, SubmittedTransaction } from "./transaction";
|
5
|
+
import { WalletAddress } from "./walletaddress";
|
6
|
+
import axios from "axios";
|
7
|
+
|
8
|
+
export interface PoolStreamOptions {
|
9
|
+
apiKey?: string;
|
10
|
+
}
|
11
|
+
|
12
|
+
export interface TransactionFilter {
|
13
|
+
start?: number;
|
14
|
+
end?: number;
|
15
|
+
from?: string;
|
16
|
+
to?: string;
|
17
|
+
limit?: number;
|
18
|
+
}
|
19
|
+
|
20
|
+
export class PoolStream {
|
21
|
+
constructor(private url: string, private options: PoolStreamOptions = {}) {}
|
22
|
+
|
23
|
+
public async transaction(
|
24
|
+
coin: string,
|
25
|
+
network: string,
|
26
|
+
txid: string
|
27
|
+
): Promise<SubmittedTransaction> {
|
28
|
+
return await axios({
|
29
|
+
method: "get",
|
30
|
+
headers: { ...this.apiKeyHeader() },
|
31
|
+
url: `${this.url}/auth/rest/v1/${coin}/${network}/transaction/${txid}`,
|
32
|
+
responseType: "json",
|
33
|
+
});
|
34
|
+
}
|
35
|
+
|
36
|
+
public async info(params: { network: string }) {
|
37
|
+
return await axios({
|
38
|
+
method: "get",
|
39
|
+
headers: { ...this.apiKeyHeader() },
|
40
|
+
url: `${this.url}/auth/rest/v1/${params.network}/info`,
|
41
|
+
responseType: "json",
|
42
|
+
});
|
43
|
+
}
|
44
|
+
|
45
|
+
public async transactions(params: {
|
46
|
+
network: string;
|
47
|
+
filter?: TransactionFilter;
|
48
|
+
contractAddress?: string;
|
49
|
+
}): Promise<Array<SubmittedTransaction>> {
|
50
|
+
const query = Object.entries(params.filter ? params.filter : {})
|
51
|
+
.filter(([_, value]) => value !== undefined)
|
52
|
+
.map(([key, value]) => `${key}=${value}`)
|
53
|
+
.join("&");
|
54
|
+
return await axios({
|
55
|
+
method: "get",
|
56
|
+
headers: { ...this.apiKeyHeader() },
|
57
|
+
url: `${this.url}/auth/rest/v1/${params.network}${
|
58
|
+
params.contractAddress ? `/${params.contractAddress}` : ""
|
59
|
+
}/transactions?${query}`,
|
60
|
+
responseType: "json",
|
61
|
+
});
|
62
|
+
}
|
63
|
+
|
64
|
+
public async balances(params: {
|
65
|
+
network: string;
|
66
|
+
addresses: string | Array<string>;
|
67
|
+
contractAddress?: string;
|
68
|
+
}): Promise<Balance> {
|
69
|
+
let query: string = "?";
|
70
|
+
|
71
|
+
if (typeof params.addresses === "string") {
|
72
|
+
query += params.addresses;
|
73
|
+
} else {
|
74
|
+
for (let i = 0; i < params.addresses.length; i++) {
|
75
|
+
query = `${i > 0 ? "&" : ""}addresses=${params.addresses}`;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
return await axios({
|
79
|
+
method: "get",
|
80
|
+
headers: { ...this.apiKeyHeader() },
|
81
|
+
url: `${this.url}/auth/rest/v1/${params.network}${
|
82
|
+
params.contractAddress ? `/${params.contractAddress}` : ""
|
83
|
+
}/balances${query}`,
|
84
|
+
responseType: "json",
|
85
|
+
});
|
86
|
+
}
|
87
|
+
|
88
|
+
public async networks(): Promise<Array<Network>> {
|
89
|
+
return await axios({
|
90
|
+
method: "get",
|
91
|
+
url: `${this.url}/networks`,
|
92
|
+
responseType: "json",
|
93
|
+
});
|
94
|
+
}
|
95
|
+
|
96
|
+
public async submitTransaction(params: {
|
97
|
+
network: string;
|
98
|
+
signedTransaction: string;
|
99
|
+
contractAddress?: string;
|
100
|
+
}): Promise<Array<string>> {
|
101
|
+
return await axios({
|
102
|
+
method: "post",
|
103
|
+
headers: { ...this.apiKeyHeader() },
|
104
|
+
url: `${this.url}/auth/rest/v1/${params.network}${
|
105
|
+
params.contractAddress ? `/${params.contractAddress}` : ""
|
106
|
+
}/submitSignedTransaction`,
|
107
|
+
responseType: "json",
|
108
|
+
data: { signedTransaction: params.signedTransaction },
|
109
|
+
});
|
110
|
+
}
|
111
|
+
|
112
|
+
public async signedAndSubmitTransaction(params: {
|
113
|
+
network: string;
|
114
|
+
transaction: SignebleTransaction;
|
115
|
+
contractAddress?: string;
|
116
|
+
}): Promise<Array<string>> {
|
117
|
+
const signedTransaction = await getCoinNetworkModule(
|
118
|
+
params.network,
|
119
|
+
false,
|
120
|
+
params.contractAddress
|
121
|
+
).signTransaction(params.transaction);
|
122
|
+
return await this.submitTransaction({
|
123
|
+
network: params.network,
|
124
|
+
signedTransaction,
|
125
|
+
contractAddress: params.contractAddress,
|
126
|
+
});
|
127
|
+
}
|
128
|
+
|
129
|
+
public async signTransaction(params: {
|
130
|
+
network: string;
|
131
|
+
transaction: SignebleTransaction;
|
132
|
+
contractAddress?: string;
|
133
|
+
}): Promise<string> {
|
134
|
+
return await getCoinNetworkModule(
|
135
|
+
params.network,
|
136
|
+
false,
|
137
|
+
params.contractAddress
|
138
|
+
).signTransaction(params.transaction);
|
139
|
+
}
|
140
|
+
|
141
|
+
public async generateWalletAddress(network: string): Promise<WalletAddress> {
|
142
|
+
const walletAddress: WalletAddress = await getCoinNetworkModule(
|
143
|
+
network
|
144
|
+
).generateWalletAddress();
|
145
|
+
return walletAddress;
|
146
|
+
}
|
147
|
+
private apiKeyHeader(): { API_KEY: string } {
|
148
|
+
if (this.options.apiKey) {
|
149
|
+
return { API_KEY: this.options.apiKey };
|
150
|
+
}
|
151
|
+
throw new Error("API_KEY is required.");
|
152
|
+
}
|
153
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
export interface Transaction {
|
2
|
+
items: Array<TransactionItem>;
|
3
|
+
fee?: number;
|
4
|
+
extra?: any;
|
5
|
+
}
|
6
|
+
|
7
|
+
export interface SignebleTransaction extends Transaction {
|
8
|
+
items: Array<TransactionItem & { secret: string }>;
|
9
|
+
}
|
10
|
+
|
11
|
+
export interface TransactionItem {
|
12
|
+
from: string;
|
13
|
+
to: string;
|
14
|
+
amount: string;
|
15
|
+
extra?: any;
|
16
|
+
}
|
17
|
+
|
18
|
+
export interface SubmittedTransaction extends Transaction {
|
19
|
+
txID: string;
|
20
|
+
confirmations: number;
|
21
|
+
decimals: number;
|
22
|
+
timestamp: number;
|
23
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { describe, expect } from "@jest/globals";
|
2
|
+
|
3
|
+
import { Ripple, XrpRipple } from "../../../src/network/ripple/ripple";
|
4
|
+
import { SignebleTransaction } from "../../../src/transaction";
|
5
|
+
|
6
|
+
describe("Ripple", () => {
|
7
|
+
const xrp: Ripple = new XrpRipple();
|
8
|
+
test("Generate Wallet", () => {
|
9
|
+
xrp.generateWalletAddress().then((wallet) => {
|
10
|
+
expect(wallet).toBeDefined();
|
11
|
+
expect(wallet.address).toBeDefined();
|
12
|
+
expect(wallet.secret).toBeDefined();
|
13
|
+
expect(wallet.raw).toBeDefined();
|
14
|
+
});
|
15
|
+
});
|
16
|
+
test("Sign Transaction", () => {
|
17
|
+
const signebleTransaction: SignebleTransaction = {
|
18
|
+
items: [
|
19
|
+
{
|
20
|
+
from: "rhFJJ3quwRJbx69UPeLYA4ZHE78fNNrHBK",
|
21
|
+
secret: "sEdSx9mDQm3cV2ta5Ey1rRrncF3VwzQ",
|
22
|
+
to: "rHzykWRVdAfEHk6c5fQxyYYHF9waQXN5Dz",
|
23
|
+
amount: "300000",
|
24
|
+
},
|
25
|
+
],
|
26
|
+
};
|
27
|
+
xrp
|
28
|
+
.signTransaction(signebleTransaction)
|
29
|
+
.then((result) => expect(result).toBeDefined());
|
30
|
+
});
|
31
|
+
});
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import { describe, expect } from "@jest/globals";
|
2
|
+
|
3
|
+
import { SignebleTransaction } from "../../../src/transaction";
|
4
|
+
import { SolSolana } from "../../../src/network/solana/solana";
|
5
|
+
|
6
|
+
describe("Solana", () => {
|
7
|
+
const sol: SolSolana = new SolSolana(true);
|
8
|
+
test("Generate Wallet", () => {
|
9
|
+
sol.generateWalletAddress().then((wallet) => {
|
10
|
+
expect(wallet).toBeDefined();
|
11
|
+
expect(wallet.address).toBeDefined();
|
12
|
+
expect(wallet.secret).toBeDefined();
|
13
|
+
expect(wallet.raw).toBeDefined();
|
14
|
+
});
|
15
|
+
});
|
16
|
+
test("Sign Transaction", () => {
|
17
|
+
const signebleTransaction: SignebleTransaction = {
|
18
|
+
items: [
|
19
|
+
{
|
20
|
+
from: "GEhoLG3dVqagLNX3UiSJ1jbQ22PJEVXSeCBU1J9aG1Jm",
|
21
|
+
secret:
|
22
|
+
"005fe7aed282313fb885c4713158f90f57a5a2a4e2ff3f31ab81f466e3efb932e261fc5d1d7ffbcbed624b519895596add389db24b2359bcd6287781209395ae",
|
23
|
+
to: "oQPnhXAbLbMuKHESaGrbXT17CyvWCpLyERSJA9HCYd7",
|
24
|
+
amount: "300000",
|
25
|
+
},
|
26
|
+
],
|
27
|
+
};
|
28
|
+
sol
|
29
|
+
.signTransaction(signebleTransaction)
|
30
|
+
.then((result) => expect(result).toBeDefined());
|
31
|
+
});
|
32
|
+
});
|
@@ -0,0 +1,56 @@
|
|
1
|
+
import { describe, expect } from "@jest/globals";
|
2
|
+
|
3
|
+
import { SignebleTransaction } from "../../../src/transaction";
|
4
|
+
import {
|
5
|
+
GenericStellar,
|
6
|
+
XlmStellar,
|
7
|
+
} from "../../../src/network/stellar/stellar";
|
8
|
+
|
9
|
+
describe("Solana", () => {
|
10
|
+
const xlm: XlmStellar = new XlmStellar(true);
|
11
|
+
test("Generate Wallet", () => {
|
12
|
+
xlm.generateWalletAddress().then((wallet) => {
|
13
|
+
expect(wallet).toBeDefined();
|
14
|
+
expect(wallet.address).toBeDefined();
|
15
|
+
expect(wallet.secret).toBeDefined();
|
16
|
+
expect(wallet.raw).toBeDefined();
|
17
|
+
});
|
18
|
+
});
|
19
|
+
test("Sign Transaction", () => {
|
20
|
+
const signebleTransaction: SignebleTransaction = {
|
21
|
+
items: [
|
22
|
+
{
|
23
|
+
from: "GB7S3QUIAE3K3T7RVH66CMMBMRYBQ4BEEGWUK3ADWGRNEVHHUIEKP7LM",
|
24
|
+
secret:
|
25
|
+
"cf297e17b5d59b3b60f2c171171cfe3738fa7c8ba671f51975e1b8ef7a150dade985bc54e3cfdbbe146fe481c46a09f6a53285980881642077c96e04e6d165f7",
|
26
|
+
to: "GDRRLB7VENXM3ZYGO5NWUIIFLFRWDYJC3B735F45D2B6TCOOWEEYN655",
|
27
|
+
amount: "300000",
|
28
|
+
},
|
29
|
+
],
|
30
|
+
};
|
31
|
+
xlm
|
32
|
+
.signTransaction(signebleTransaction)
|
33
|
+
.then((result) => expect(result).toBeDefined());
|
34
|
+
});
|
35
|
+
|
36
|
+
test("Sign Transaction with contract", () => {
|
37
|
+
const generic: GenericStellar = new GenericStellar(
|
38
|
+
"GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
|
39
|
+
true
|
40
|
+
);
|
41
|
+
const signebleTransaction: SignebleTransaction = {
|
42
|
+
items: [
|
43
|
+
{
|
44
|
+
from: "GB7S3QUIAE3K3T7RVH66CMMBMRYBQ4BEEGWUK3ADWGRNEVHHUIEKP7LM",
|
45
|
+
secret:
|
46
|
+
"cf297e17b5d59b3b60f2c171171cfe3738fa7c8ba671f51975e1b8ef7a150dade985bc54e3cfdbbe146fe481c46a09f6a53285980881642077c96e04e6d165f7",
|
47
|
+
to: "GDRRLB7VENXM3ZYGO5NWUIIFLFRWDYJC3B735F45D2B6TCOOWEEYN655",
|
48
|
+
amount: "300000",
|
49
|
+
},
|
50
|
+
],
|
51
|
+
};
|
52
|
+
generic
|
53
|
+
.signTransaction(signebleTransaction)
|
54
|
+
.then((result) => expect(result).toBeDefined());
|
55
|
+
});
|
56
|
+
});
|
@@ -0,0 +1,53 @@
|
|
1
|
+
import { describe, expect } from "@jest/globals";
|
2
|
+
|
3
|
+
import { SignebleTransaction } from "../../../src/transaction";
|
4
|
+
import { GenericTron, TrxTron } from "../../../src/network/tron/tron";
|
5
|
+
|
6
|
+
describe("Solana", () => {
|
7
|
+
const xlm: TrxTron = new TrxTron(true);
|
8
|
+
test("Generate Wallet", () => {
|
9
|
+
xlm.generateWalletAddress().then((wallet) => {
|
10
|
+
expect(wallet).toBeDefined();
|
11
|
+
expect(wallet.address).toBeDefined();
|
12
|
+
expect(wallet.secret).toBeDefined();
|
13
|
+
expect(wallet.raw).toBeDefined();
|
14
|
+
});
|
15
|
+
});
|
16
|
+
test("Sign Transaction", () => {
|
17
|
+
const signebleTransaction: SignebleTransaction = {
|
18
|
+
items: [
|
19
|
+
{
|
20
|
+
from: "TEKzMAQ9TcMZFQj83V5TKg4dHgAHJT7EeB",
|
21
|
+
secret:
|
22
|
+
"AE4DD4F51C1CE099D58BBC5EB693C7B6F747706D3C8AF71078A8B0B65FB203BF",
|
23
|
+
to: "TM1zzNDZD2DPASbKcgdVoTYhfmYgtfwx9R",
|
24
|
+
amount: "300000",
|
25
|
+
},
|
26
|
+
],
|
27
|
+
};
|
28
|
+
xlm
|
29
|
+
.signTransaction(signebleTransaction)
|
30
|
+
.then((result) => expect(result).toBeDefined());
|
31
|
+
});
|
32
|
+
|
33
|
+
test("Sign Transaction with contract", () => {
|
34
|
+
const generic: GenericTron = new GenericTron(
|
35
|
+
"TG3XXyExBkPp9nzdajDZsozEu4BkaSJozs",
|
36
|
+
true
|
37
|
+
);
|
38
|
+
const signebleTransaction: SignebleTransaction = {
|
39
|
+
items: [
|
40
|
+
{
|
41
|
+
from: "TEKzMAQ9TcMZFQj83V5TKg4dHgAHJT7EeB",
|
42
|
+
secret:
|
43
|
+
"AE4DD4F51C1CE099D58BBC5EB693C7B6F747706D3C8AF71078A8B0B65FB203BF",
|
44
|
+
to: "TM1zzNDZD2DPASbKcgdVoTYhfmYgtfwx9R",
|
45
|
+
amount: "300000",
|
46
|
+
},
|
47
|
+
],
|
48
|
+
};
|
49
|
+
generic
|
50
|
+
.signTransaction(signebleTransaction)
|
51
|
+
.then((result) => expect(result).toBeDefined());
|
52
|
+
});
|
53
|
+
});
|
package/tests.js
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
const { TronWeb } = require("tronweb");
|
2
|
+
const tronWeb = new TronWeb({
|
3
|
+
fullHost: "https://api.trongrid.io",
|
4
|
+
});
|
5
|
+
tronWeb.setAddress("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t");
|
6
|
+
(async () => {
|
7
|
+
const usdtContract = await tronWeb
|
8
|
+
.contract()
|
9
|
+
.at("TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t");
|
10
|
+
|
11
|
+
const symbol = await usdtContract.methods.symbol().call();
|
12
|
+
console.log(symbol);
|
13
|
+
})();
|
package/tsconfig.json
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"outDir": "./dist",
|
4
|
+
"rootDir": "./src",
|
5
|
+
"strict": true,
|
6
|
+
"noImplicitOverride": true,
|
7
|
+
"noPropertyAccessFromIndexSignature": true,
|
8
|
+
"noImplicitReturns": true,
|
9
|
+
"noFallthroughCasesInSwitch": false,
|
10
|
+
"skipLibCheck": true,
|
11
|
+
"esModuleInterop": true,
|
12
|
+
"sourceMap": true,
|
13
|
+
"declaration": false,
|
14
|
+
"experimentalDecorators": true,
|
15
|
+
"importHelpers": true,
|
16
|
+
"useDefineForClassFields": false,
|
17
|
+
"allowSyntheticDefaultImports": true,
|
18
|
+
"moduleResolution": "bundler",
|
19
|
+
"module": "ES2022",
|
20
|
+
"target": "ES2022"
|
21
|
+
},
|
22
|
+
"include": ["src/**/*"],
|
23
|
+
"exclude": ["node_modules", "**/__tests__/*"]
|
24
|
+
}
|