@leofcoin/endpoints 0.3.1 → 0.3.3
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/LICENSE +20 -20
- package/exports/api.md +336 -251
- package/exports/http.d.ts +6 -0
- package/exports/http.js +142 -191
- package/exports/shared.d.ts +20 -0
- package/exports/shared.js +33 -34
- package/exports/ws.d.ts +5 -0
- package/exports/ws.js +111 -114
- package/package.json +44 -33
- package/.gitattributes +0 -2
package/exports/ws.js
CHANGED
|
@@ -1,114 +1,111 @@
|
|
|
1
|
-
import Server from 'socket-request-server'
|
|
2
|
-
import {formatUnits} from '@leofcoin/utils'
|
|
3
|
-
import shared from './shared.js'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
send
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
send(
|
|
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
|
-
|
|
1
|
+
import Server from 'socket-request-server';
|
|
2
|
+
import { formatUnits } from '@leofcoin/utils';
|
|
3
|
+
import shared from './shared.js';
|
|
4
|
+
export default (chain, port, networkVersion, remote = false) => {
|
|
5
|
+
return Server({ port, protocol: networkVersion }, {
|
|
6
|
+
network: async ({ send }) => {
|
|
7
|
+
send({ version: networkVersion });
|
|
8
|
+
},
|
|
9
|
+
networkStats: async ({ send }) => {
|
|
10
|
+
send(await shared.networkStats(chain, networkVersion));
|
|
11
|
+
},
|
|
12
|
+
balances: async ({ send }) => send(await chain.balances),
|
|
13
|
+
balanceOf: async ({ address, format = false }, { send }) => {
|
|
14
|
+
const balance = (await chain.balances)[address];
|
|
15
|
+
if (balance)
|
|
16
|
+
send(format ? formatUnits(balance) : balance);
|
|
17
|
+
else
|
|
18
|
+
send(0);
|
|
19
|
+
},
|
|
20
|
+
getNonce: async ({ address }, { send }) => send(await chain.getNonce(address)),
|
|
21
|
+
selectedAccount: ({ send }) => {
|
|
22
|
+
if (remote)
|
|
23
|
+
send(globalThis.peernet.selectedAccount);
|
|
24
|
+
else
|
|
25
|
+
send(405);
|
|
26
|
+
},
|
|
27
|
+
selectAccount: async ({ address }, { send }) => {
|
|
28
|
+
if (remote)
|
|
29
|
+
try {
|
|
30
|
+
await globalThis.walletStore.put('selected-account', address);
|
|
31
|
+
send(200);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
send(404);
|
|
35
|
+
}
|
|
36
|
+
else
|
|
37
|
+
send(405);
|
|
38
|
+
},
|
|
39
|
+
accounts: async ({ send }) => {
|
|
40
|
+
if (remote)
|
|
41
|
+
send(JSON.parse(new TextDecoder().decode(await globalThis.walletStore.get('accounts'))));
|
|
42
|
+
else
|
|
43
|
+
send(405);
|
|
44
|
+
},
|
|
45
|
+
hasTransactionToHandle: async ({ send }) => send(await chain.hasTransactionToHandle()),
|
|
46
|
+
getBlock: async ({ index }, { send }) => send(await chain.getBlock(index)),
|
|
47
|
+
blocks: async ({ amount }, { send }) => {
|
|
48
|
+
send(await chain.getBlocks(amount));
|
|
49
|
+
},
|
|
50
|
+
sendTransaction: async (transaction, { send }) => {
|
|
51
|
+
try {
|
|
52
|
+
const tx = await chain.sendTransaction(transaction);
|
|
53
|
+
await tx.wait();
|
|
54
|
+
delete tx.wait;
|
|
55
|
+
send(tx);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
send(202);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
peerId: ({ send }) => send(globalThis.peernet.peerId),
|
|
62
|
+
peers: ({ send }) => send(globalThis.peernet.peers.map(([id, peer]) => id)),
|
|
63
|
+
validators: ({ send }) => send(chain.validators),
|
|
64
|
+
lookup: async ({ name }, { send }) => send(await chain.lookup(name)),
|
|
65
|
+
staticCall: async ({ contract, method, params }, { send }) => send(await chain.staticCall(contract, method, params)),
|
|
66
|
+
nativeBurns: async ({ send }) => send(await chain.nativeBurns),
|
|
67
|
+
contracts: async ({ send }) => send(await chain.contracts),
|
|
68
|
+
nativeMints: async ({ send }) => send(await chain.nativeMints),
|
|
69
|
+
nativeToken: async ({ send }) => send(await chain.nativeToken),
|
|
70
|
+
nativeTransfers: async ({ send }) => send(await chain.nativeTransfers),
|
|
71
|
+
totalSize: async ({ send }) => send(await chain.totalSize),
|
|
72
|
+
totalTransactions: async ({ send }) => send(await chain.totalTransactions),
|
|
73
|
+
totalBlocks: async ({ send }) => send(chain.totalBlocks),
|
|
74
|
+
lastBlock: async (ctx) => (ctx.body = await chain.lastBlock),
|
|
75
|
+
nativeCalls: async ({ send }) => send(await chain.nativeCalls),
|
|
76
|
+
participating: async ({ send }) => send(await chain.participating),
|
|
77
|
+
poolTransactions: async ({ send }) => send(await globalThis.transactionPoolStore.get()),
|
|
78
|
+
transactionsInPool: async ({ send }) => send(await globalThis.transactionPoolStore.length()),
|
|
79
|
+
transactionPoolSize: async ({ send }) => send(await globalThis.transactionPoolStore.size()),
|
|
80
|
+
participate: async ({ address }, { send }) => {
|
|
81
|
+
if (remote)
|
|
82
|
+
send(await chain.participate(address));
|
|
83
|
+
else
|
|
84
|
+
send(405);
|
|
85
|
+
},
|
|
86
|
+
deployContract: async ({ transaction, contract }, { send }) => {
|
|
87
|
+
try {
|
|
88
|
+
const tx = await chain.deployContract(contract, transaction);
|
|
89
|
+
await tx.wait();
|
|
90
|
+
delete tx.wait;
|
|
91
|
+
send(tx);
|
|
92
|
+
}
|
|
93
|
+
catch (error) {
|
|
94
|
+
send(error.message);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
createContractAddress: async ({ owner, code, params }, { send }) => {
|
|
98
|
+
try {
|
|
99
|
+
const address = await chain.createContractAddress(owner, code, params);
|
|
100
|
+
send(address);
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
send(error);
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
blockHashMap: async (ctx) => (ctx.body = chain.blockHashMap),
|
|
107
|
+
bootstrap: async ({ send }) => {
|
|
108
|
+
send(await shared.bootstrap());
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
};
|
package/package.json
CHANGED
|
@@ -1,33 +1,44 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@leofcoin/endpoints",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"exports": {
|
|
7
|
-
"./api": "./exports/api.md",
|
|
8
|
-
"./http": "./exports/http.js",
|
|
9
|
-
"./ws": "./exports/ws.js"
|
|
10
|
-
},
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@leofcoin/endpoints",
|
|
3
|
+
"version": "0.3.3",
|
|
4
|
+
"description": "",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./api": "./exports/api.md",
|
|
8
|
+
"./http": "./exports/http.js",
|
|
9
|
+
"./ws": "./exports/ws.js"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"./exports"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "npx tsc",
|
|
16
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [],
|
|
19
|
+
"author": "",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/leofcoin/endpoints.git"
|
|
24
|
+
},
|
|
25
|
+
"bugs": {
|
|
26
|
+
"url": "https://github.com/leofcoin/endpoints/issues"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/leofcoin/endpoints#readme",
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@koa/cors": "^5.0.0",
|
|
31
|
+
"@koa/router": "^12.0.0",
|
|
32
|
+
"@leofcoin/utils": "^1.1.10",
|
|
33
|
+
"koa": "^2.14.1",
|
|
34
|
+
"showdown": "^2.1.0",
|
|
35
|
+
"socket-request-server": "^1.6.3"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/koa__cors": "^4.0.1",
|
|
39
|
+
"@types/koa__router": "^12.0.1",
|
|
40
|
+
"@types/node": "^20.8.6",
|
|
41
|
+
"@types/showdown": "^2.0.2",
|
|
42
|
+
"typescript": "^5.2.2"
|
|
43
|
+
}
|
|
44
|
+
}
|
package/.gitattributes
DELETED