@leofcoin/endpoint-clients 0.3.8 → 0.3.10

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.
@@ -0,0 +1,157 @@
1
+ import { formatUnits, BigNumber } from '@leofcoin/utils';
2
+
3
+ class Client {
4
+ url;
5
+ networkVersion;
6
+ client;
7
+ constructor(url = 'ws://localhost:4040', networkVersion = 'leofcoin-peach') {
8
+ this.url = url;
9
+ this.networkVersion = networkVersion;
10
+ }
11
+ get pubsub() {
12
+ return {
13
+ publish: globalThis.pubsub.publish,
14
+ subscribe: globalThis.pubsub.subscribe
15
+ };
16
+ }
17
+ balances() {
18
+ return chain.balances;
19
+ }
20
+ async balanceOf(address, format) {
21
+ const balances = await chain.balances;
22
+ const balance = balances[address];
23
+ return format ? formatUnits(balance) : balance;
24
+ }
25
+ selectedAccount() {
26
+ return peernet.selectedAccount;
27
+ }
28
+ async selectAccount(address) {
29
+ try {
30
+ await globalThis.walletStore.put('selected-account', address);
31
+ }
32
+ catch (error) {
33
+ throw new Error(`couldn't set selected account`);
34
+ }
35
+ }
36
+ accounts() {
37
+ return chain.accounts;
38
+ }
39
+ hasTransactionToHandle() {
40
+ return chain.hasTransactionToHandle();
41
+ }
42
+ getBlock(index) {
43
+ return chain.getBlock(index);
44
+ }
45
+ blocks(amount) {
46
+ return globalThis.blockStore.values(amount);
47
+ }
48
+ sendTransaction(transaction) {
49
+ return chain.sendTransaction(transaction);
50
+ }
51
+ peerId() {
52
+ return peernet.peerId;
53
+ }
54
+ peers() {
55
+ return peernet.peers;
56
+ }
57
+ validators() {
58
+ return chain.validators;
59
+ }
60
+ lookup(name) {
61
+ return chain.lookup(name);
62
+ }
63
+ staticCall(contract, method, params) {
64
+ return chain.staticCall(contract, method, params);
65
+ }
66
+ nativeBurns() {
67
+ return chain.nativeBurns;
68
+ }
69
+ contracts() {
70
+ return chain.contracts;
71
+ }
72
+ nativeMints() {
73
+ return chain.nativeMints;
74
+ }
75
+ nativeToken() {
76
+ return chain.nativeToken;
77
+ }
78
+ nativeTransfers() {
79
+ return chain.nativeTransfers;
80
+ }
81
+ totalSize() {
82
+ return chain.totalSize;
83
+ }
84
+ totalTransactions() {
85
+ return chain.totalTransactions;
86
+ }
87
+ poolTransactions() {
88
+ return transactionPoolStore.get();
89
+ }
90
+ transactionsInPool() {
91
+ return transactionPoolStore.length();
92
+ }
93
+ transactionPoolSize() {
94
+ return transactionPoolStore.size();
95
+ }
96
+ totalBlocks() {
97
+ return chain.totalBlocks;
98
+ }
99
+ nativeCalls() {
100
+ return chain.nativeCalls;
101
+ }
102
+ participating() {
103
+ return chain.participating;
104
+ }
105
+ participate(address) {
106
+ return chain.participate(address);
107
+ }
108
+ createContractAddress(owner, code, params) {
109
+ return chain.createContractAddress(owner, code, params);
110
+ }
111
+ deployContract(code, params) {
112
+ return chain.deployContract(code, params);
113
+ }
114
+ network() {
115
+ return chain.network;
116
+ }
117
+ async networkStats() {
118
+ let accountsHolding = 0;
119
+ let accountsHoldingAmount = BigNumber.from(0);
120
+ let topHolders = [];
121
+ const balances = Object.entries(await chain.balances)
122
+ .map(([holder, amount]) => {
123
+ amount = BigNumber.from(amount);
124
+ return { holder, amount };
125
+ })
126
+ .sort((a, b) => formatUnits(b.amount.sub(a.amount)));
127
+ for (let { holder, amount } of balances) {
128
+ if (amount.gt(0)) {
129
+ accountsHoldingAmount = accountsHoldingAmount.add(amount);
130
+ accountsHolding += 1;
131
+ topHolders.length < 100 && topHolders.push({ holder, amount: formatUnits(amount) });
132
+ }
133
+ }
134
+ return {
135
+ version: peernet.networkVersion,
136
+ peers: peernet.peers.map(([id, peer]) => id),
137
+ accounts: await accountsStore.length(),
138
+ accountsHolding,
139
+ accountsHoldingAmount: formatUnits(accountsHoldingAmount).toString(),
140
+ topHolders
141
+ };
142
+ }
143
+ getNonce(address) {
144
+ return chain.getNonce(address);
145
+ }
146
+ lastBlock() {
147
+ return chain.lastBlock;
148
+ }
149
+ blockHashMap() {
150
+ return chain.blockHashMap;
151
+ }
152
+ bootstrap() {
153
+ return chain.blockHashMap;
154
+ }
155
+ }
156
+
157
+ export { Client as default };
@@ -0,0 +1,135 @@
1
+ class Client {
2
+ url;
3
+ networkVersion;
4
+ get isHttpClient() {
5
+ return true;
6
+ }
7
+ constructor(url, networkVersion) {
8
+ this.url = url;
9
+ this.networkVersion = networkVersion;
10
+ }
11
+ async _fetch(method, params, type = 'json') {
12
+ params = new URLSearchParams(params).toString();
13
+ const response = await fetch(`${this.url}/${method}?${params}`);
14
+ return response[type]();
15
+ }
16
+ async _fetchString(method, params) {
17
+ return String(await this._fetch(method, params, 'text'));
18
+ }
19
+ async _fetchNumber(method, params) {
20
+ return Number(await this._fetchString(method, params));
21
+ }
22
+ async _fetchBoolean(method, params) {
23
+ return Boolean((await this._fetchString(method, params)) === 'true');
24
+ }
25
+ balances() {
26
+ return this._fetch('balances');
27
+ }
28
+ balanceOf(address, format) {
29
+ return this._fetch(`balanceOf`, { address, format });
30
+ }
31
+ selectedAccount() {
32
+ return this._fetchString('selectedAccount');
33
+ }
34
+ selectAccount(address) {
35
+ return this._fetch('selectAccount', { address });
36
+ }
37
+ accounts() {
38
+ return this._fetch('accounts');
39
+ }
40
+ hasTransactionToHandle() {
41
+ return this._fetchBoolean('hasTransactionToHandle');
42
+ }
43
+ getBlock(index) {
44
+ return this._fetch('getBlock', { index });
45
+ }
46
+ blocks(amount) {
47
+ return this._fetch('blocks', { amount });
48
+ }
49
+ sendTransaction(transaction) {
50
+ return this._fetch('sendTransaction', transaction);
51
+ }
52
+ peerId() {
53
+ return this._fetchString('peerId');
54
+ }
55
+ peers() {
56
+ return this._fetch('peers');
57
+ }
58
+ validators() {
59
+ return this._fetch('validators');
60
+ }
61
+ lookup(name) {
62
+ return this._fetch('lookup', { name });
63
+ }
64
+ staticCall(contract, method, params) {
65
+ return this._fetch('staticCall', { contract, method, params });
66
+ }
67
+ nativeBurns() {
68
+ return this._fetchNumber('nativeBurns');
69
+ }
70
+ contracts() {
71
+ return this._fetch('contracts');
72
+ }
73
+ nativeMints() {
74
+ return this._fetchNumber('nativeMints');
75
+ }
76
+ nativeToken() {
77
+ return this._fetchString('nativeToken');
78
+ }
79
+ nativeTransfers() {
80
+ return this._fetchNumber('nativeTransfers');
81
+ }
82
+ totalSize() {
83
+ return this._fetchNumber('totalSize');
84
+ }
85
+ totalTransactions() {
86
+ return this._fetchNumber('totalTransactions');
87
+ }
88
+ poolTransactions() {
89
+ return this._fetch('poolTransactions');
90
+ }
91
+ transactionsInPool() {
92
+ return this._fetchNumber('transactionsInPool');
93
+ }
94
+ transactionPoolSize() {
95
+ return this._fetchNumber('transactionPoolSize');
96
+ }
97
+ totalBlocks() {
98
+ return this._fetchNumber('totalBlocks');
99
+ }
100
+ nativeCalls() {
101
+ return this._fetchNumber('nativeCalls');
102
+ }
103
+ participating() {
104
+ return this._fetchBoolean('participating');
105
+ }
106
+ participate(address) {
107
+ return this._fetch('participate', { address });
108
+ }
109
+ createContractAddress(owner, code, params) {
110
+ return this._fetch('createContractAddress', { owner, code, params });
111
+ }
112
+ deployContract(code, params) {
113
+ return this._fetch('deployContract', { code, params });
114
+ }
115
+ network() {
116
+ return this._fetch('network');
117
+ }
118
+ networkStats() {
119
+ return this._fetch('networkStats');
120
+ }
121
+ getNonce(address) {
122
+ return this._fetchNumber('getNonce', { address });
123
+ }
124
+ lastBlock() {
125
+ return this._fetch('lastBlock');
126
+ }
127
+ blockHashMap() {
128
+ return this._fetch('blockHashMap');
129
+ }
130
+ bootstrap() {
131
+ return this._fetch('blockHashMap');
132
+ }
133
+ }
134
+
135
+ export { Client as default };
@@ -0,0 +1,5 @@
1
+ export { default as ws } from './ws.js';
2
+ export { default as http } from './http.js';
3
+ export { default as direct } from './direct.js';
4
+ import 'socket-request-client';
5
+ import '@leofcoin/utils';
@@ -0,0 +1,53 @@
1
+ export default class Client {
2
+ url: string;
3
+ networkVersion: string;
4
+ client: any;
5
+ constructor(url?: string, networkVersion?: string);
6
+ get pubsub(): {
7
+ publish: any;
8
+ subscribe: any;
9
+ };
10
+ balances(): any;
11
+ balanceOf(address: string, format: boolean): Promise<any>;
12
+ selectedAccount(): any;
13
+ selectAccount(address: any): Promise<void>;
14
+ accounts(): any;
15
+ hasTransactionToHandle(): any;
16
+ getBlock(index: number): any;
17
+ blocks(amount: number): any;
18
+ sendTransaction(transaction: any): any;
19
+ peerId(): any;
20
+ peers(): any;
21
+ validators(): any;
22
+ lookup(name: string): any;
23
+ staticCall(contract: string, method: string, params: {}): any;
24
+ nativeBurns(): number;
25
+ contracts(): number;
26
+ nativeMints(): number;
27
+ nativeToken(): string;
28
+ nativeTransfers(): number;
29
+ totalSize(): number;
30
+ totalTransactions(): number;
31
+ poolTransactions(): any;
32
+ transactionsInPool(): any;
33
+ transactionPoolSize(): any;
34
+ totalBlocks(): number;
35
+ nativeCalls(): number;
36
+ participating(): boolean;
37
+ participate(address: string): {};
38
+ createContractAddress(owner: string, code: string, params: {}): {};
39
+ deployContract(code: string, params: {}): {};
40
+ network(): any;
41
+ networkStats(): Promise<{
42
+ version: string;
43
+ peers: {}[];
44
+ accounts: number;
45
+ accountsHolding: number;
46
+ accountsHoldingAmount: number;
47
+ topHolders: any[];
48
+ }>;
49
+ getNonce(address: string): any;
50
+ lastBlock(): any;
51
+ blockHashMap(): any;
52
+ bootstrap(): any;
53
+ }
@@ -0,0 +1,54 @@
1
+ type responseType = 'json' | 'text' | 'arrayBuffer' | 'clone' | 'formData' | 'blob';
2
+ type networkVersion = 'peach' | string;
3
+ export default class Client {
4
+ url: string;
5
+ networkVersion: networkVersion;
6
+ get isHttpClient(): boolean;
7
+ constructor(url: any, networkVersion: any);
8
+ _fetch(method: string, params?: any, type?: responseType): Promise<any>;
9
+ _fetchString(method: string, params?: any): Promise<string>;
10
+ _fetchNumber(method: string, params?: any): Promise<number>;
11
+ _fetchBoolean(method: string, params?: any): Promise<boolean>;
12
+ balances(): Promise<any>;
13
+ balanceOf(address: any, format: any): Promise<any>;
14
+ selectedAccount(): Promise<string>;
15
+ selectAccount(address: any): Promise<any>;
16
+ accounts(): Promise<any>;
17
+ hasTransactionToHandle(): Promise<boolean>;
18
+ getBlock(index: any): Promise<any>;
19
+ blocks(amount: any): Promise<any>;
20
+ sendTransaction(transaction: any): Promise<any>;
21
+ peerId(): Promise<string>;
22
+ peers(): Promise<any>;
23
+ validators(): Promise<any>;
24
+ lookup(name: any): Promise<any>;
25
+ staticCall(contract: any, method: any, params: any): Promise<any>;
26
+ nativeBurns(): Promise<number>;
27
+ contracts(): Promise<any>;
28
+ nativeMints(): Promise<number>;
29
+ nativeToken(): Promise<string>;
30
+ nativeTransfers(): Promise<number>;
31
+ totalSize(): Promise<number>;
32
+ totalTransactions(): Promise<number>;
33
+ poolTransactions(): Promise<any>;
34
+ transactionsInPool(): Promise<number>;
35
+ transactionPoolSize(): Promise<number>;
36
+ totalBlocks(): Promise<number>;
37
+ nativeCalls(): Promise<number>;
38
+ participating(): Promise<boolean>;
39
+ participate(address: any): Promise<any>;
40
+ createContractAddress(owner: any, code: any, params: any): Promise<any>;
41
+ deployContract(code: any, params: any): Promise<any>;
42
+ network(): Promise<any>;
43
+ networkStats(): Promise<{
44
+ version: string;
45
+ peers: {}[];
46
+ accounts: number;
47
+ accountsHolding: number;
48
+ }>;
49
+ getNonce(address: string): Promise<number>;
50
+ lastBlock(): Promise<any>;
51
+ blockHashMap(): Promise<any>;
52
+ bootstrap(): Promise<any>;
53
+ }
54
+ export {};
@@ -0,0 +1,3 @@
1
+ export { default as ws } from './ws.js';
2
+ export { default as http } from './http.js';
3
+ export { default as direct } from './direct.js';
@@ -0,0 +1,54 @@
1
+ import ClientConnection from 'socket-request-client/connection';
2
+ export default class Client {
3
+ url: string;
4
+ networkVersion: string;
5
+ client: ClientConnection;
6
+ constructor(url?: string, networkVersion?: string);
7
+ init(): Promise<void>;
8
+ get pubsub(): {
9
+ publish: (topic: string, value: any) => Promise<any>;
10
+ subscribe: (topic: string, cb: any) => Promise<any>;
11
+ };
12
+ request(url: string, params?: {}): Promise<any>;
13
+ balances(): Promise<any>;
14
+ balanceOf(address: string, format: boolean): Promise<any>;
15
+ selectedAccount(): Promise<any>;
16
+ selectAccount(address: any): Promise<any>;
17
+ accounts(): Promise<any>;
18
+ hasTransactionToHandle(): Promise<any>;
19
+ getBlock(index: number): Promise<any>;
20
+ blocks(amount: number): Promise<any>;
21
+ sendTransaction(transaction: any): Promise<any>;
22
+ peerId(): Promise<any>;
23
+ peers(): Promise<any>;
24
+ validators(): Promise<any>;
25
+ lookup(name: string): Promise<any>;
26
+ staticCall(contract: string, method: string, params: {}): Promise<any>;
27
+ nativeBurns(): Promise<number>;
28
+ contracts(): Promise<number>;
29
+ nativeMints(): Promise<number>;
30
+ nativeToken(): Promise<string>;
31
+ nativeTransfers(): Promise<number>;
32
+ totalSize(): Promise<number>;
33
+ totalTransactions(): Promise<number>;
34
+ poolTransactions(): Promise<any>;
35
+ transactionsInPool(): Promise<any>;
36
+ transactionPoolSize(): Promise<any>;
37
+ totalBlocks(): Promise<number>;
38
+ nativeCalls(): Promise<number>;
39
+ participating(): Promise<boolean>;
40
+ participate(address: string): {};
41
+ createContractAddress(owner: string, code: string, params: {}): {};
42
+ deployContract(code: string, params: {}): {};
43
+ network(): Promise<any>;
44
+ networkStats(): Promise<{
45
+ version: string;
46
+ peers: {}[];
47
+ accounts: number;
48
+ accountsHolding: number;
49
+ }>;
50
+ getNonce(address: string): Promise<any>;
51
+ lastBlock(): Promise<any>;
52
+ blockHashMap(): Promise<any>;
53
+ bootstrap(): Promise<any>;
54
+ }
package/exports/ws.js ADDED
@@ -0,0 +1,134 @@
1
+ import { SocketRequestClient } from 'socket-request-client';
2
+
3
+ class Client {
4
+ url;
5
+ networkVersion;
6
+ client;
7
+ constructor(url = 'ws://localhost:4040', networkVersion = 'leofcoin-peach') {
8
+ this.url = url;
9
+ this.networkVersion = networkVersion;
10
+ }
11
+ async init() {
12
+ const client = new SocketRequestClient(this.url, this.networkVersion);
13
+ this.client = (await client.init());
14
+ }
15
+ get pubsub() {
16
+ return {
17
+ publish: this.client.pubsub.publish,
18
+ subscribe: this.client.pubsub.subscribe
19
+ };
20
+ }
21
+ request(url, params) {
22
+ return this.client.request({ url, params });
23
+ }
24
+ balances() {
25
+ return this.request('balances');
26
+ }
27
+ balanceOf(address, format) {
28
+ return this.request('balanceOf', { address, format });
29
+ }
30
+ selectedAccount() {
31
+ return this.request('selectedAccount');
32
+ }
33
+ selectAccount(address) {
34
+ return this.request('selectAccount', { address });
35
+ }
36
+ accounts() {
37
+ return this.request('accounts');
38
+ }
39
+ hasTransactionToHandle() {
40
+ return this.request('hasTransactionToHandle');
41
+ }
42
+ getBlock(index) {
43
+ return this.request('getBlock', { index });
44
+ }
45
+ blocks(amount) {
46
+ return this.request('blocks', { amount });
47
+ }
48
+ sendTransaction(transaction) {
49
+ return this.request('sendTransaction', transaction);
50
+ }
51
+ peerId() {
52
+ return this.request('peerId');
53
+ }
54
+ peers() {
55
+ return this.request('peers');
56
+ }
57
+ validators() {
58
+ return this.request('validators');
59
+ }
60
+ lookup(name) {
61
+ return this.request('lookup', { name });
62
+ }
63
+ staticCall(contract, method, params) {
64
+ return this.request('staticCall', { contract, method, params });
65
+ }
66
+ nativeBurns() {
67
+ return this.request('nativeBurns');
68
+ }
69
+ contracts() {
70
+ return this.request('contracts');
71
+ }
72
+ nativeMints() {
73
+ return this.request('nativeMints');
74
+ }
75
+ nativeToken() {
76
+ return this.request('nativeToken');
77
+ }
78
+ nativeTransfers() {
79
+ return this.request('nativeTransfers');
80
+ }
81
+ totalSize() {
82
+ return this.request('totalSize');
83
+ }
84
+ totalTransactions() {
85
+ return this.request('totalTransactions');
86
+ }
87
+ poolTransactions() {
88
+ return this.request('poolTransactions');
89
+ }
90
+ transactionsInPool() {
91
+ return this.request('transactionsInPool');
92
+ }
93
+ transactionPoolSize() {
94
+ return this.request('transactionPoolSize');
95
+ }
96
+ totalBlocks() {
97
+ return this.request('totalBlocks');
98
+ }
99
+ nativeCalls() {
100
+ return this.request('nativeCalls');
101
+ }
102
+ participating() {
103
+ return this.request('participating');
104
+ }
105
+ participate(address) {
106
+ return this.request('participate', { address });
107
+ }
108
+ createContractAddress(owner, code, params) {
109
+ return this.request('createContractAddress', { owner, code, params });
110
+ }
111
+ deployContract(code, params) {
112
+ return this.request('deployContract', { code, params });
113
+ }
114
+ network() {
115
+ return this.request('network');
116
+ }
117
+ networkStats() {
118
+ return this.request('networkStats');
119
+ }
120
+ getNonce(address) {
121
+ return this.request('getNonce', { address });
122
+ }
123
+ lastBlock() {
124
+ return this.request('lastBlock');
125
+ }
126
+ blockHashMap() {
127
+ return this.request('blockHashMap');
128
+ }
129
+ bootstrap() {
130
+ return this.request('blockHashMap');
131
+ }
132
+ }
133
+
134
+ export { Client as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/endpoint-clients",
3
- "version": "0.3.8",
3
+ "version": "0.3.10",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -23,6 +23,9 @@
23
23
  "./http.js": "./exports/http.js",
24
24
  "./direct.js": "./exports/direct.js"
25
25
  },
26
+ "files": [
27
+ "exports"
28
+ ],
26
29
  "types": "./exports/types/index.d.ts",
27
30
  "type": "module",
28
31
  "scripts": {
package/.gitattributes DELETED
@@ -1,2 +0,0 @@
1
- # Auto detect text files and perform LF normalization
2
- * text=auto
package/.prettierrc DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "tabWidth": 2,
3
- "semi": false,
4
- "singleQuote": true,
5
- "printWidth": 120,
6
- "trailingComma": "none"
7
- }
package/rollup.config.js DELETED
@@ -1,14 +0,0 @@
1
- import typescript from '@rollup/plugin-typescript'
2
- export default [{
3
- input: ['./src/index.ts', './src/http.ts', './src/ws.ts', './src/direct.ts'],
4
- output: {
5
- dir: './exports',
6
- format: 'es'
7
- },
8
- plugins: [
9
- typescript()
10
- ],
11
- external: [
12
- './identity.js'
13
- ]
14
- }]
package/src/direct.ts DELETED
@@ -1,185 +0,0 @@
1
- import { formatUnits, BigNumber } from '@leofcoin/utils'
2
-
3
- declare var chain
4
- declare var peernet
5
- declare var transactionPoolStore
6
- declare var accountsStore
7
-
8
- export default class Client {
9
- url: string
10
- networkVersion: string
11
- client
12
-
13
- constructor(url = 'ws://localhost:4040', networkVersion = 'leofcoin-peach') {
14
- this.url = url
15
- this.networkVersion = networkVersion
16
- }
17
-
18
- get pubsub() {
19
- return {
20
- publish: globalThis.pubsub.publish,
21
- subscribe: globalThis.pubsub.subscribe
22
- }
23
- }
24
-
25
- balances() {
26
- return chain.balances
27
- }
28
-
29
- async balanceOf(address: string, format: boolean) {
30
- const balances = await chain.balances
31
- const balance = balances[address]
32
- return format ? formatUnits(balance) : balance
33
- }
34
-
35
- selectedAccount() {
36
- return peernet.selectedAccount
37
- }
38
-
39
- async selectAccount(address: any) {
40
- try {
41
- await globalThis.walletStore.put('selected-account', address)
42
- } catch (error) {
43
- throw new Error(`couldn't set selected account`)
44
- }
45
- }
46
-
47
- accounts() {
48
- return chain.accounts
49
- }
50
-
51
- hasTransactionToHandle() {
52
- return chain.hasTransactionToHandle()
53
- }
54
-
55
- getBlock(index: number) {
56
- return chain.getBlock(index)
57
- }
58
-
59
- blocks(amount: number) {
60
- return chain.getBlocks(amount)
61
- }
62
-
63
- sendTransaction(transaction) {
64
- return chain.sendTransaction(transaction)
65
- }
66
- peerId() {
67
- return peernet.peerId
68
- }
69
- peers() {
70
- return peernet.peers
71
- }
72
- validators() {
73
- return chain.validators
74
- }
75
- lookup(name: string) {
76
- return chain.lookup(name)
77
- }
78
-
79
- staticCall(contract: string, method: string, params: {}) {
80
- return chain.staticCall(contract, method, params)
81
- }
82
- nativeBurns(): number {
83
- return chain.nativeBurns
84
- }
85
- contracts(): number {
86
- return chain.contracts
87
- }
88
- nativeMints(): number {
89
- return chain.nativeMints
90
- }
91
- nativeToken(): string {
92
- return chain.nativeToken
93
- }
94
- nativeTransfers(): number {
95
- return chain.nativeTransfers
96
- }
97
- totalSize(): number {
98
- return chain.totalSize
99
- }
100
- totalTransactions(): number {
101
- return chain.totalTransactions
102
- }
103
- poolTransactions() {
104
- return transactionPoolStore.get()
105
- }
106
- transactionsInPool() {
107
- return transactionPoolStore.length()
108
- }
109
- transactionPoolSize() {
110
- return transactionPoolStore.size()
111
- }
112
- totalBlocks(): number {
113
- return chain.totalBlocks
114
- }
115
- nativeCalls(): number {
116
- return chain.nativeCalls
117
- }
118
- participating(): boolean {
119
- return chain.participating
120
- }
121
- participate(address: string): {} {
122
- return chain.participate(address)
123
- }
124
- createContractAddress(owner: string, code: string, params: {}): {} {
125
- return chain.createContractAddress(owner, code, params)
126
- }
127
- deployContract(code: string, params: {}): {} {
128
- return chain.deployContract(code, params)
129
- }
130
- network() {
131
- return chain.network
132
- }
133
-
134
- async networkStats(): Promise<{
135
- version: string
136
- peers: {}[]
137
- accounts: number
138
- accountsHolding: number
139
- accountsHoldingAmount: number
140
- topHolders: any[]
141
- }> {
142
- let accountsHolding = 0
143
- let accountsHoldingAmount = BigNumber.from(0)
144
- let topHolders = []
145
- const balances = Object.entries(await chain.balances)
146
- .map(([holder, amount]): { holder: string; amount: BigNumber } => {
147
- amount = BigNumber.from(amount)
148
- return { holder, amount }
149
- })
150
- .sort((a, b) => formatUnits(b.amount.sub(a.amount)))
151
-
152
- for (let { holder, amount } of balances) {
153
- if (amount.gt(0)) {
154
- accountsHoldingAmount = accountsHoldingAmount.add(amount)
155
- accountsHolding += 1
156
- topHolders.length < 100 && topHolders.push({ holder, amount: formatUnits(amount) })
157
- }
158
- }
159
-
160
- return {
161
- version: peernet.networkVersion,
162
- peers: peernet.peers.map(([id, peer]) => id),
163
- accounts: await accountsStore.length(),
164
- accountsHolding,
165
- accountsHoldingAmount: formatUnits(accountsHoldingAmount).toString(),
166
- topHolders
167
- }
168
- }
169
-
170
- getNonce(address: string) {
171
- return chain.getNonce(address)
172
- }
173
-
174
- lastBlock() {
175
- return chain.lastBlock
176
- }
177
-
178
- blockHashMap() {
179
- return chain.blockHashMap
180
- }
181
-
182
- bootstrap() {
183
- return chain.blockHashMap
184
- }
185
- }
package/src/http.ts DELETED
@@ -1,159 +0,0 @@
1
- // see https://developer.mozilla.org/en-US/docs/Web/API/Response#instance_methods
2
- type responseType = 'json' | 'text' | 'arrayBuffer' | 'clone' | 'formData' | 'blob'
3
- type networkVersion = 'peach' | string
4
-
5
- export default class Client {
6
- url: string
7
- networkVersion: networkVersion
8
- get isHttpClient() {
9
- return true
10
- }
11
-
12
- constructor(url, networkVersion) {
13
- this.url = url
14
- this.networkVersion = networkVersion
15
- }
16
-
17
- async _fetch(method: string, params?, type: responseType = 'json') {
18
- params = new URLSearchParams(params).toString()
19
- const response = await fetch(`${this.url}/${method}?${params}`)
20
- return response[type]()
21
- }
22
-
23
- async _fetchString(method: string, params?) {
24
- return String(await this._fetch(method, params, 'text'))
25
- }
26
-
27
- async _fetchNumber(method: string, params?) {
28
- return Number(await this._fetchString(method, params))
29
- }
30
-
31
- async _fetchBoolean(method: string, params?) {
32
- return Boolean((await this._fetchString(method, params)) === 'true')
33
- }
34
-
35
- balances() {
36
- return this._fetch('balances')
37
- }
38
-
39
- balanceOf(address, format) {
40
- return this._fetch(`balanceOf`, { address, format })
41
- }
42
-
43
- selectedAccount() {
44
- return this._fetchString('selectedAccount')
45
- }
46
-
47
- selectAccount(address) {
48
- return this._fetch('selectAccount', { address })
49
- }
50
-
51
- accounts() {
52
- return this._fetch('accounts')
53
- }
54
-
55
- hasTransactionToHandle() {
56
- return this._fetchBoolean('hasTransactionToHandle')
57
- }
58
-
59
- getBlock(index) {
60
- return this._fetch('getBlock', { index })
61
- }
62
- blocks(amount) {
63
- return this._fetch('blocks', { amount })
64
- }
65
-
66
- sendTransaction(transaction) {
67
- return this._fetch('sendTransaction', transaction)
68
- }
69
- peerId() {
70
- return this._fetchString('peerId')
71
- }
72
- peers() {
73
- return this._fetch('peers')
74
- }
75
- validators() {
76
- return this._fetch('validators')
77
- }
78
- lookup(name) {
79
- return this._fetch('lookup', { name })
80
- }
81
-
82
- staticCall(contract, method, params) {
83
- return this._fetch('staticCall', { contract, method, params })
84
- }
85
- nativeBurns() {
86
- return this._fetchNumber('nativeBurns')
87
- }
88
- contracts() {
89
- return this._fetch('contracts')
90
- }
91
- nativeMints() {
92
- return this._fetchNumber('nativeMints')
93
- }
94
- nativeToken() {
95
- return this._fetchString('nativeToken')
96
- }
97
- nativeTransfers() {
98
- return this._fetchNumber('nativeTransfers')
99
- }
100
- totalSize() {
101
- return this._fetchNumber('totalSize')
102
- }
103
- totalTransactions() {
104
- return this._fetchNumber('totalTransactions')
105
- }
106
- poolTransactions() {
107
- return this._fetch('poolTransactions')
108
- }
109
- transactionsInPool() {
110
- return this._fetchNumber('transactionsInPool')
111
- }
112
- transactionPoolSize() {
113
- return this._fetchNumber('transactionPoolSize')
114
- }
115
- totalBlocks() {
116
- return this._fetchNumber('totalBlocks')
117
- }
118
- nativeCalls() {
119
- return this._fetchNumber('nativeCalls')
120
- }
121
- participating() {
122
- return this._fetchBoolean('participating')
123
- }
124
- participate(address) {
125
- return this._fetch('participate', { address })
126
- }
127
-
128
- createContractAddress(owner, code, params) {
129
- return this._fetch('createContractAddress', { owner, code, params })
130
- }
131
-
132
- deployContract(code, params) {
133
- return this._fetch('deployContract', { code, params })
134
- }
135
-
136
- network() {
137
- return this._fetch('network')
138
- }
139
-
140
- networkStats(): Promise<{ version: string; peers: {}[]; accounts: number; accountsHolding: number }> {
141
- return this._fetch('networkStats')
142
- }
143
-
144
- getNonce(address: string) {
145
- return this._fetchNumber('getNonce', { address })
146
- }
147
-
148
- lastBlock() {
149
- return this._fetch('lastBlock')
150
- }
151
-
152
- blockHashMap() {
153
- return this._fetch('blockHashMap')
154
- }
155
-
156
- bootstrap() {
157
- return this._fetch('blockHashMap')
158
- }
159
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export { default as ws } from './ws.js'
2
- export { default as http } from './http.js'
3
- export { default as direct } from './direct.js'
package/src/ws.ts DELETED
@@ -1,156 +0,0 @@
1
- import { SocketRequestClient } from 'socket-request-client'
2
- import ClientConnection from 'socket-request-client/connection'
3
-
4
- export default class Client {
5
- url: string
6
- networkVersion: string
7
- client: ClientConnection
8
-
9
- constructor(url = 'ws://localhost:4040', networkVersion = 'leofcoin-peach') {
10
- this.url = url
11
- this.networkVersion = networkVersion
12
- }
13
-
14
- async init() {
15
- const client = new SocketRequestClient(this.url, this.networkVersion)
16
- this.client = (await client.init()) as ClientConnection
17
- }
18
-
19
- get pubsub() {
20
- return {
21
- publish: this.client.pubsub.publish,
22
- subscribe: this.client.pubsub.subscribe
23
- }
24
- }
25
-
26
- request(url: string, params?: {}) {
27
- return this.client.request({ url, params })
28
- }
29
-
30
- balances() {
31
- return this.request('balances')
32
- }
33
-
34
- balanceOf(address: string, format: boolean) {
35
- return this.request('balanceOf', { address, format })
36
- }
37
-
38
- selectedAccount() {
39
- return this.request('selectedAccount')
40
- }
41
-
42
- selectAccount(address: any) {
43
- return this.request('selectAccount', { address })
44
- }
45
-
46
- accounts() {
47
- return this.request('accounts')
48
- }
49
-
50
- hasTransactionToHandle() {
51
- return this.request('hasTransactionToHandle')
52
- }
53
-
54
- getBlock(index: number) {
55
- return this.request('getBlock', { index })
56
- }
57
- blocks(amount: number) {
58
- return this.request('blocks', { amount })
59
- }
60
-
61
- sendTransaction(transaction) {
62
- return this.request('sendTransaction', transaction)
63
- }
64
- peerId() {
65
- return this.request('peerId')
66
- }
67
- peers() {
68
- return this.request('peers')
69
- }
70
- validators() {
71
- return this.request('validators')
72
- }
73
- lookup(name: string) {
74
- return this.request('lookup', { name })
75
- }
76
-
77
- staticCall(contract: string, method: string, params: {}) {
78
- return this.request('staticCall', { contract, method, params })
79
- }
80
- nativeBurns(): Promise<number> {
81
- return this.request('nativeBurns')
82
- }
83
- contracts(): Promise<number> {
84
- return this.request('contracts')
85
- }
86
- nativeMints(): Promise<number> {
87
- return this.request('nativeMints')
88
- }
89
- nativeToken(): Promise<string> {
90
- return this.request('nativeToken')
91
- }
92
- nativeTransfers(): Promise<number> {
93
- return this.request('nativeTransfers')
94
- }
95
- totalSize(): Promise<number> {
96
- return this.request('totalSize')
97
- }
98
- totalTransactions(): Promise<number> {
99
- return this.request('totalTransactions')
100
- }
101
- poolTransactions() {
102
- return this.request('poolTransactions')
103
- }
104
- transactionsInPool() {
105
- return this.request('transactionsInPool')
106
- }
107
- transactionPoolSize() {
108
- return this.request('transactionPoolSize')
109
- }
110
- totalBlocks(): Promise<number> {
111
- return this.request('totalBlocks')
112
- }
113
- nativeCalls(): Promise<number> {
114
- return this.request('nativeCalls')
115
- }
116
- participating(): Promise<boolean> {
117
- return this.request('participating')
118
- }
119
- participate(address: string): {} {
120
- return this.request('participate', { address })
121
- }
122
- createContractAddress(owner: string, code: string, params: {}): {} {
123
- return this.request('createContractAddress', { owner, code, params })
124
- }
125
- deployContract(code: string, params: {}): {} {
126
- return this.request('deployContract', { code, params })
127
- }
128
- network() {
129
- return this.request('network')
130
- }
131
-
132
- networkStats(): Promise<{
133
- version: string
134
- peers: {}[]
135
- accounts: number
136
- accountsHolding: number
137
- }> {
138
- return this.request('networkStats')
139
- }
140
-
141
- getNonce(address: string) {
142
- return this.request('getNonce', { address })
143
- }
144
-
145
- lastBlock() {
146
- return this.request('lastBlock')
147
- }
148
-
149
- blockHashMap() {
150
- return this.request('blockHashMap')
151
- }
152
-
153
- bootstrap() {
154
- return this.request('blockHashMap')
155
- }
156
- }
package/test/index.js DELETED
@@ -1,17 +0,0 @@
1
- import { needsImplementations } from './spec.js';
2
- import WsClient from './../exports/ws.js'
3
- import HttpClient from './../exports/http.js'
4
- import DirectClient from './../exports/direct.js'
5
-
6
- try {
7
- const wsNeeds = needsImplementations(new WsClient())
8
- if (wsNeeds.length > 0) throw new Error(`ws: missing implementations ${wsNeeds.length > 2 ? wsNeeds.join(', ') : wsNeeds.join(' & ')}`)
9
-
10
- const httpNeeds = needsImplementations(new HttpClient())
11
- if (httpNeeds.length > 0) throw new Error(`http: missing implementations ${httpNeeds.length > 2 ? httpNeeds.join(', ') : httpNeeds.join(' & ')}`)
12
-
13
- const directNeeds = needsImplementations(new DirectClient())
14
- if (directNeeds.length > 0) throw new Error(`direct: missing implementations ${directNeeds.length > 2 ? directNeeds.join(', ') : directNeeds.join(' & ')}`)
15
- } catch (error) {
16
- console.error(error);
17
- }
package/test/spec.js DELETED
@@ -1,45 +0,0 @@
1
- export const implementations = [
2
- 'accounts',
3
- 'balanceOf',
4
- 'balances',
5
- 'blocks',
6
- 'contracts',
7
- 'createContractAddress',
8
- 'createTransactionFrom',
9
- 'deployContract',
10
- 'getBlock',
11
- 'hasTransactionToHandle',
12
- 'lookup',
13
- 'nativeBurns',
14
- 'nativeCalls',
15
- 'nativeMints',
16
- 'nativeToken',
17
- 'nativeTransfers',
18
- 'participate',
19
- 'participating',
20
- 'peerId',
21
- 'peers',
22
- 'pubsub',
23
- 'selectAccount',
24
- 'selectedAccount',
25
- 'staticCall',
26
- 'totalBlocks',
27
- 'totalSize',
28
- 'totalTransactions',
29
- 'validators',
30
- 'lastBlock'
31
- ]
32
-
33
- export const needsImplementations = (client) => {
34
- const needs = []
35
- for (const key of implementations) {
36
- try {
37
- if (!client[key] && key === 'pubsub' && !client.isHttpClient) needs.push(key)
38
- } catch (error) {
39
- if (error.message !== "Cannot read properties of undefined (reading 'pubsub')") throw new Error(error)
40
- }
41
-
42
- }
43
- console.log(needs);
44
- return needs
45
- }
package/tsconfig.json DELETED
@@ -1,16 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "NodeNext",
4
- "target": "es2022",
5
- "outDir": "./exports",
6
- "moduleResolution":"NodeNext",
7
- "allowJs": true,
8
- "declaration": true,
9
- "declarationDir": "./exports/types",
10
- "allowSyntheticDefaultImports": true,
11
- "resolveJsonModule": true
12
- },
13
- "include": [
14
- "./src/**/*"
15
- ]
16
- }