@leofcoin/endpoint-clients 0.2.6 → 0.2.8

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,146 @@
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 chain.selectedAccount;
27
+ }
28
+ selectAccount(address) {
29
+ return chain.selectAccount({ address });
30
+ }
31
+ accounts() {
32
+ return chain.accounts;
33
+ }
34
+ hasTransactionToHandle() {
35
+ return chain.hasTransactionToHandle();
36
+ }
37
+ getBlock(index) {
38
+ return chain.getBlock(index);
39
+ }
40
+ blocks(amount) {
41
+ return chain.blocks.slice(amount);
42
+ }
43
+ sendTransaction(transaction) {
44
+ return chain.sendTransaction(transaction);
45
+ }
46
+ peerId() {
47
+ return peernet.peerId;
48
+ }
49
+ peers() {
50
+ return peernet.peers;
51
+ }
52
+ validators() {
53
+ return chain.validators;
54
+ }
55
+ lookup(name) {
56
+ return chain.lookup(name);
57
+ }
58
+ staticCall(contract, method, params) {
59
+ return chain.staticCall(contract, method, params);
60
+ }
61
+ nativeBurns() {
62
+ return chain.nativeBurns;
63
+ }
64
+ contracts() {
65
+ return chain.contracts;
66
+ }
67
+ nativeMints() {
68
+ return chain.nativeMints;
69
+ }
70
+ nativeToken() {
71
+ return chain.nativeToken;
72
+ }
73
+ nativeTransfers() {
74
+ return chain.nativeTransfers;
75
+ }
76
+ totalSize() {
77
+ return chain.totalSize;
78
+ }
79
+ totalTransactions() {
80
+ return chain.totalTransactions;
81
+ }
82
+ poolTransactions() {
83
+ return transactionPoolStore.get();
84
+ }
85
+ transactionsInPool() {
86
+ return transactionPoolStore.length();
87
+ }
88
+ transactionPoolSize() {
89
+ return transactionPoolStore.size();
90
+ }
91
+ totalBlocks() {
92
+ return chain.blocks.length;
93
+ }
94
+ nativeCalls() {
95
+ return chain.nativeCalls;
96
+ }
97
+ participating() {
98
+ return chain.participating;
99
+ }
100
+ participate(address) {
101
+ return chain.participate(address);
102
+ }
103
+ createContractAddress(owner, code, params) {
104
+ return chain.createContractAddress(owner, code, params);
105
+ }
106
+ deployContract(code, params) {
107
+ return chain.deployContract(code, params);
108
+ }
109
+ network() {
110
+ return chain.network;
111
+ }
112
+ async networkStats() {
113
+ let accountsHolding = 0;
114
+ let accountsHoldingAmount = BigNumber.from(0);
115
+ let topHolders = [];
116
+ const balances = Object.entries(await chain.balances)
117
+ .map(([holder, amount]) => {
118
+ amount = BigNumber.from(amount);
119
+ return { holder, amount };
120
+ })
121
+ .sort((a, b) => formatUnits(b.amount.sub(a.amount)));
122
+ for (let { holder, amount } of balances) {
123
+ if (amount.gt(0)) {
124
+ accountsHoldingAmount = accountsHoldingAmount.add(amount);
125
+ accountsHolding += 1;
126
+ topHolders.length < 100 && topHolders.push({ holder, amount: formatUnits(amount) });
127
+ }
128
+ }
129
+ return {
130
+ version: peernet.networkVersion,
131
+ peers: peernet.peers.map(([id, peer]) => id),
132
+ accounts: await accountsStore.length(),
133
+ accountsHolding,
134
+ accountsHoldingAmount: formatUnits(accountsHoldingAmount).toString(),
135
+ topHolders
136
+ };
137
+ }
138
+ getNonce(address) {
139
+ return chain.getNonce(address);
140
+ }
141
+ lastBlock() {
142
+ return chain.lastBlock;
143
+ }
144
+ }
145
+
146
+ export { Client as default };
package/exports/http.js CHANGED
@@ -121,6 +121,8 @@ class Client {
121
121
  getNonce(address) {
122
122
  return this._fetchNumber('getNonce', { address });
123
123
  }
124
+ lastBlock() {
125
+ }
124
126
  }
125
127
 
126
128
  export { Client as default };
package/exports/index.js CHANGED
@@ -1,3 +1,5 @@
1
1
  export { default as ws } from './ws.js';
2
2
  export { default as http } from './http.js';
3
+ export { default as direct } from './direct.js';
3
4
  import 'socket-request-client';
5
+ import '@leofcoin/utils';
@@ -0,0 +1,51 @@
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): any;
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(): number;
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
+ }
@@ -47,5 +47,6 @@ export default class Client {
47
47
  accountsHolding: number;
48
48
  }>;
49
49
  getNonce(address: string): Promise<number>;
50
+ lastBlock(): void;
50
51
  }
51
52
  export {};
@@ -1,2 +1,3 @@
1
1
  export { default as ws } from './ws.js';
2
2
  export { default as http } from './http.js';
3
+ export { default as direct } from './direct.js';
@@ -1,8 +1,8 @@
1
- import socketRequestClient from 'socket-request-client';
1
+ import SocketRequestClient from 'socket-request-client';
2
2
  export default class Client {
3
3
  url: string;
4
4
  networkVersion: string;
5
- client: socketRequestClient;
5
+ client: SocketRequestClient;
6
6
  constructor(url?: string, networkVersion?: string);
7
7
  init(): Promise<void>;
8
8
  get pubsub(): {
package/exports/ws.js CHANGED
@@ -1,4 +1,4 @@
1
- import socketRequestClient from 'socket-request-client';
1
+ import SocketRequestClient from 'socket-request-client';
2
2
 
3
3
  class Client {
4
4
  url;
@@ -9,7 +9,7 @@ class Client {
9
9
  this.networkVersion = networkVersion;
10
10
  }
11
11
  async init() {
12
- this.client = await socketRequestClient(this.url, this.networkVersion);
12
+ this.client = await new SocketRequestClient(this.url, this.networkVersion);
13
13
  }
14
14
  get pubsub() {
15
15
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/endpoint-clients",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -15,8 +15,13 @@
15
15
  "import": "./exports/http.js",
16
16
  "types": "./exports/types/http.d.ts"
17
17
  },
18
+ "./direct": {
19
+ "import": "./exports/direct.js",
20
+ "types": "./exports/types/direct.d.ts"
21
+ },
18
22
  "./ws.js": "./exports/ws.js",
19
- "./http.js": "./exports/http.js"
23
+ "./http.js": "./exports/http.js",
24
+ "./direct.js": "./exports/direct.js"
20
25
  },
21
26
  "types": "./exports/types/index.d.ts",
22
27
  "type": "module",
@@ -41,6 +46,7 @@
41
46
  "tslib": "^2.5.0"
42
47
  },
43
48
  "dependencies": {
44
- "socket-request-client": "^1.7.3"
49
+ "@leofcoin/utils": "^1.1.7",
50
+ "socket-request-client": "^1.7.5"
45
51
  }
46
52
  }
package/rollup.config.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import typescript from '@rollup/plugin-typescript'
2
2
  import tsConfig from './tsconfig.json' assert { type: 'json'}
3
3
  export default [{
4
- input: ['./src/index.ts', './src/http.ts', './src/ws.ts'],
4
+ input: ['./src/index.ts', './src/http.ts', './src/ws.ts', './src/direct.ts'],
5
5
  output: {
6
6
  dir: './exports',
7
7
  format: 'es'
package/src/direct.ts ADDED
@@ -0,0 +1,165 @@
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 chain.selectedAccount
37
+ }
38
+
39
+ selectAccount(address: any) {
40
+ return chain.selectAccount({address})
41
+ }
42
+
43
+ accounts() {
44
+ return chain.accounts
45
+ }
46
+
47
+ hasTransactionToHandle() {
48
+ return chain.hasTransactionToHandle()
49
+ }
50
+
51
+ getBlock(index: number) {
52
+ return chain.getBlock(index)
53
+ }
54
+ blocks(amount: number) {
55
+ return chain.blocks.slice(amount)
56
+ }
57
+
58
+ sendTransaction(transaction) {
59
+ return chain.sendTransaction(transaction)
60
+ }
61
+ peerId() {
62
+ return peernet.peerId
63
+ }
64
+ peers() {
65
+ return peernet.peers
66
+ }
67
+ validators() {
68
+ return chain.validators
69
+ }
70
+ lookup(name: string) {
71
+ return chain.lookup(name)
72
+ }
73
+
74
+ staticCall(contract: string, method: string, params: {}) {
75
+ return chain.staticCall(contract, method, params)
76
+ }
77
+ nativeBurns(): number {
78
+ return chain.nativeBurns
79
+ }
80
+ contracts(): number {
81
+ return chain.contracts
82
+ }
83
+ nativeMints(): number {
84
+ return chain.nativeMints
85
+ }
86
+ nativeToken(): number {
87
+ return chain.nativeToken
88
+ }
89
+ nativeTransfers(): number {
90
+ return chain.nativeTransfers
91
+ }
92
+ totalSize(): number {
93
+ return chain.totalSize
94
+ }
95
+ totalTransactions(): number {
96
+ return chain.totalTransactions
97
+ }
98
+ poolTransactions() {
99
+ return transactionPoolStore.get()
100
+ }
101
+ transactionsInPool() {
102
+ return transactionPoolStore.length()
103
+ }
104
+ transactionPoolSize() {
105
+ return transactionPoolStore.size()
106
+ }
107
+ totalBlocks(): number {
108
+ return chain.blocks.length
109
+ }
110
+ nativeCalls(): number {
111
+ return chain.nativeCalls
112
+ }
113
+ participating(): boolean {
114
+ return chain.participating
115
+ }
116
+ participate(address: string): {} {
117
+ return chain.participate(address)
118
+ }
119
+ createContractAddress(owner: string, code: string, params: {}): {} {
120
+ return chain.createContractAddress(owner, code, params)
121
+ }
122
+ deployContract(code: string, params: {}): {} {
123
+ return chain.deployContract(code, params)
124
+ }
125
+ network() {
126
+ return chain.network
127
+ }
128
+
129
+ async networkStats(): Promise<{ version: string; peers: {}[]; accounts: number; accountsHolding: number, accountsHoldingAmount: number, topHolders: any[] }> {
130
+ let accountsHolding = 0
131
+ let accountsHoldingAmount = BigNumber.from(0)
132
+ let topHolders = []
133
+ const balances = Object.entries(await chain.balances)
134
+ .map(([holder, amount]) => {
135
+ amount = BigNumber.from(amount)
136
+ return {holder, amount}
137
+ })
138
+ .sort((a, b) => formatUnits(b.amount.sub(a.amount)))
139
+
140
+ for (let {holder, amount} of balances) {
141
+ if (amount.gt(0)) {
142
+ accountsHoldingAmount = accountsHoldingAmount.add(amount)
143
+ accountsHolding += 1
144
+ topHolders.length < 100 && topHolders.push({holder, amount: formatUnits(amount)})
145
+ }
146
+ }
147
+
148
+ return {
149
+ version: peernet.networkVersion,
150
+ peers: peernet.peers.map(([id, peer]) => id),
151
+ accounts: await accountsStore.length(),
152
+ accountsHolding,
153
+ accountsHoldingAmount: formatUnits(accountsHoldingAmount).toString(),
154
+ topHolders
155
+ }
156
+ }
157
+
158
+ getNonce(address: string) {
159
+ return chain.getNonce(address)
160
+ }
161
+
162
+ lastBlock() {
163
+ return chain.lastBlock
164
+ }
165
+ }
package/src/http.ts CHANGED
@@ -145,4 +145,8 @@ export default class Client {
145
145
  getNonce(address: string) {
146
146
  return this._fetchNumber('getNonce', { address })
147
147
  }
148
+
149
+ lastBlock() {
150
+
151
+ }
148
152
  }
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export {default as ws} from './ws.js'
2
- export {default as http} from './http.js'
2
+ export {default as http} from './http.js'
3
+ export {default as direct} from './direct.js'
package/src/ws.ts CHANGED
@@ -1,9 +1,9 @@
1
- import socketRequestClient from 'socket-request-client'
1
+ import SocketRequestClient from 'socket-request-client'
2
2
 
3
3
  export default class Client {
4
4
  url: string
5
5
  networkVersion: string
6
- client: socketRequestClient
6
+ client: SocketRequestClient
7
7
 
8
8
  constructor(url = 'ws://localhost:4040', networkVersion = 'leofcoin-peach') {
9
9
  this.url = url
@@ -11,7 +11,7 @@ export default class Client {
11
11
  }
12
12
 
13
13
  async init() {
14
- this.client = await socketRequestClient(this.url, this.networkVersion)
14
+ this.client = await new SocketRequestClient(this.url, this.networkVersion)
15
15
  }
16
16
 
17
17
  get pubsub() {
package/test/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { needsImplementations } from './spec.js';
2
2
  import WsClient from './../exports/ws.js'
3
3
  import HttpClient from './../exports/http.js'
4
+ import DirectClient from './../exports/direct.js'
4
5
 
5
6
  try {
6
7
  const wsNeeds = needsImplementations(new WsClient())
@@ -8,6 +9,9 @@ try {
8
9
 
9
10
  const httpNeeds = needsImplementations(new HttpClient())
10
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(' & ')}`)
11
15
  } catch (error) {
12
16
  console.error(error);
13
17
  }
package/test/spec.js CHANGED
@@ -26,7 +26,8 @@ export const implementations = [
26
26
  'totalBlocks',
27
27
  'totalSize',
28
28
  'totalTransactions',
29
- 'validators'
29
+ 'validators',
30
+ 'lastBlock'
30
31
  ]
31
32
 
32
33
  export const needsImplementations = (client) => {
@@ -39,5 +40,6 @@ export const needsImplementations = (client) => {
39
40
  }
40
41
 
41
42
  }
43
+ console.log(needs);
42
44
  return needs
43
45
  }
package/tsconfig.json CHANGED
@@ -12,6 +12,5 @@
12
12
  },
13
13
  "include": [
14
14
  "./src/**/*"
15
- ],
16
- "exclude": ["./node_modules"]
15
+ ]
17
16
  }