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