@leofcoin/endpoint-clients 0.3.6 → 0.3.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.
- package/.prettierrc +7 -0
- package/LICENSE +20 -20
- package/README.md +208 -208
- package/package.json +52 -52
- package/rollup.config.js +14 -14
- package/src/direct.ts +185 -177
- package/src/http.ts +159 -160
- package/src/index.ts +3 -3
- package/src/ws.ts +156 -151
- package/test/index.js +16 -16
- package/test/spec.js +44 -44
- package/tsconfig.json +15 -15
- package/exports/direct.js +0 -157
- package/exports/http.js +0 -135
- package/exports/index.js +0 -5
- package/exports/types/direct.d.ts +0 -53
- package/exports/types/http.d.ts +0 -54
- package/exports/types/index.d.ts +0 -3
- package/exports/types/ws.d.ts +0 -54
- package/exports/ws.js +0 -134
package/src/direct.ts
CHANGED
|
@@ -1,177 +1,185 @@
|
|
|
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.
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
return chain.
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return chain.
|
|
176
|
-
}
|
|
177
|
-
|
|
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
|
+
}
|