@leofcoin/endpoints 0.3.1 → 0.3.2
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/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/api.md +0 -251
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 vandeurenglenn
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 vandeurenglenn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
package/exports/http.js
CHANGED
|
@@ -1,193 +1,144 @@
|
|
|
1
|
-
import koa from 'koa'
|
|
2
|
-
import cors from '@koa/cors'
|
|
3
|
-
import Router from '@koa/router'
|
|
4
|
-
import {formatUnits} from '@leofcoin/utils'
|
|
5
|
-
import {readFile} from 'fs/promises'
|
|
6
|
-
import Showdown from 'showdown'
|
|
7
|
-
import shared from './shared.js'
|
|
8
|
-
import { dirname, join} from 'path'
|
|
9
|
-
import { fileURLToPath } from 'url'
|
|
10
|
-
|
|
1
|
+
import koa from 'koa';
|
|
2
|
+
import cors from '@koa/cors';
|
|
3
|
+
import Router from '@koa/router';
|
|
4
|
+
import { formatUnits } from '@leofcoin/utils';
|
|
5
|
+
import { readFile } from 'fs/promises';
|
|
6
|
+
import Showdown from 'showdown';
|
|
7
|
+
import shared from './shared.js';
|
|
8
|
+
import { dirname, join } from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
11
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
12
11
|
const __dirname = dirname(__filename);
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
ctx.body = peernet.peers.map(([id, peer]) => id)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
ctx.body = await chain.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
ctx.body = await chain.
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
ctx.body = chain.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
ctx.body =
|
|
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
|
-
ctx.body =
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
router.get('/nativeCalls', ctx =>
|
|
148
|
-
ctx.body = chain.nativeCalls
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
router.get('/participating', ctx =>
|
|
152
|
-
ctx.body = chain.participating
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
router.get('/participate', async ctx =>
|
|
156
|
-
ctx.body = await chain.participate(ctx.query.address)
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
router.get('/deployContract', async ctx => {
|
|
160
|
-
try {
|
|
161
|
-
const tx = await chain.deployContract(ctx.query.code, ctx.query.params)
|
|
162
|
-
await tx.wait()
|
|
163
|
-
delete tx.wait
|
|
164
|
-
ctx.body = JSON.stringify(tx)
|
|
165
|
-
} catch (error) {
|
|
166
|
-
|
|
167
|
-
}
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
router.get('/createContractAddress', async ctx => {
|
|
171
|
-
try {
|
|
172
|
-
const address = await chain.createContractAddress(ctx.query.owner, ctx.query.code, ctx.query.params)
|
|
173
|
-
ctx.body = address
|
|
174
|
-
} catch (error) {
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
router.get('/lastBlock', async ctx => ctx.body = chain.lastBlock)
|
|
180
|
-
|
|
181
|
-
router.get('/blockHashMap', async ctx => ctx.body = chain.blockHashMap)
|
|
182
|
-
|
|
183
|
-
router.get('/bootstrap', async ctx => {
|
|
184
|
-
ctx.body = (await shared.bootstrap()).map(value => Array.from(value.toString()))
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
// todo finish ...
|
|
188
|
-
api.use(cors('*'))
|
|
189
|
-
api.use(router.routes())
|
|
190
|
-
api.listen(port)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
12
|
+
const api = new koa();
|
|
13
|
+
const router = new Router();
|
|
14
|
+
const converter = new Showdown.Converter();
|
|
15
|
+
const apiFile = await readFile(join(__dirname, './api.md'));
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* ensure remote is set to false when serving on a server
|
|
19
|
+
*/
|
|
20
|
+
export default (chain, port, networkVersion, remote = false) => {
|
|
21
|
+
// api routes
|
|
22
|
+
router.get('/', (ctx) => {
|
|
23
|
+
ctx.body = converter.makeHtml(apiFile.toString());
|
|
24
|
+
});
|
|
25
|
+
router.get('/network', (ctx) => {
|
|
26
|
+
ctx.body = {
|
|
27
|
+
version: networkVersion
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
router.get('/networkStats', async (ctx) => {
|
|
31
|
+
ctx.body = await shared.networkStats(chain, networkVersion);
|
|
32
|
+
});
|
|
33
|
+
router.get('/balances', async (ctx) => {
|
|
34
|
+
ctx.body = await chain.balances;
|
|
35
|
+
});
|
|
36
|
+
router.get('/balanceOf', async (ctx) => {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
const balance = (await chain.balances)[ctx.query.address];
|
|
39
|
+
if (balance)
|
|
40
|
+
ctx.body = ctx.query.format ? formatUnits(balance) : balance;
|
|
41
|
+
else
|
|
42
|
+
ctx.body = 0;
|
|
43
|
+
});
|
|
44
|
+
router.get('/selectedAccount', (ctx) => {
|
|
45
|
+
if (remote)
|
|
46
|
+
ctx.body = globalThis.peernet.selectedAccount;
|
|
47
|
+
else
|
|
48
|
+
ctx.status = 405;
|
|
49
|
+
});
|
|
50
|
+
router.get('/selectAccount', async (ctx) => {
|
|
51
|
+
if (remote) {
|
|
52
|
+
globalThis.peernet.selectedAccount = ctx.query.address;
|
|
53
|
+
try {
|
|
54
|
+
await globalThis.walletStore.put('selected-account', ctx.query.address);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
ctx.body = error.message;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
ctx.status = 405;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
router.get('/accounts', async (ctx) => {
|
|
65
|
+
if (remote)
|
|
66
|
+
ctx.body = JSON.parse(new TextDecoder().decode(await globalThis.walletStore.get('accounts')));
|
|
67
|
+
else
|
|
68
|
+
ctx.status = 405;
|
|
69
|
+
});
|
|
70
|
+
router.get('/hasTransactionToHandle', async (ctx) => {
|
|
71
|
+
ctx.body = await chain.hasTransactionToHandle();
|
|
72
|
+
});
|
|
73
|
+
router.get('/getNonce', async (ctx) => {
|
|
74
|
+
ctx.body = await chain.getNonce(ctx.query.address);
|
|
75
|
+
});
|
|
76
|
+
router.get('/getBlock', async (ctx) => (ctx.body = await chain.getBlock(ctx.query.index)));
|
|
77
|
+
router.get('/blocks', async (ctx) => {
|
|
78
|
+
ctx.body = chain.getBlocks(ctx.query.amount);
|
|
79
|
+
});
|
|
80
|
+
router.get('/sendTransaction', async (ctx) => {
|
|
81
|
+
try {
|
|
82
|
+
const tx = await chain.sendTransaction(ctx.query.transaction);
|
|
83
|
+
await tx.wait();
|
|
84
|
+
delete tx.wait;
|
|
85
|
+
ctx.body = tx;
|
|
86
|
+
}
|
|
87
|
+
catch (error) {
|
|
88
|
+
// ctx(202)
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
router.get('/peerId', (ctx) => (ctx.body = globalThis.peernet.peerId));
|
|
92
|
+
router.get('/validators', (ctx) => (ctx.body = chain.validators));
|
|
93
|
+
router.get('/peers', (ctx) => (ctx.body = globalThis.peernet.peers.map(([id, peer]) => id)));
|
|
94
|
+
router.get('/lookup', async (ctx) => {
|
|
95
|
+
ctx.body = await chain.lookup(ctx.query.name);
|
|
96
|
+
});
|
|
97
|
+
router.get('/staticCall', async (ctx) => (ctx.body = await chain.staticCall(ctx.query.contract, ctx.query.method, ctx.query.params)));
|
|
98
|
+
router.get('/nativeBurns', async (ctx) => (ctx.body = await chain.nativeBurns));
|
|
99
|
+
router.get('/contracts', async (ctx) => (ctx.body = await chain.contracts));
|
|
100
|
+
router.get('/nativeMints', async (ctx) => (ctx.body = await chain.nativeMints));
|
|
101
|
+
router.get('/nativeToken', async (ctx) => (ctx.body = await chain.nativeToken));
|
|
102
|
+
router.get('/nativeTransfers', async (ctx) => (ctx.body = await chain.nativeTransfers));
|
|
103
|
+
router.get('/totalSize', async (ctx) => (ctx.body = await chain.totalSize));
|
|
104
|
+
router.get('/totalTransactions', async (ctx) => (ctx.body = await chain.totalTransactions));
|
|
105
|
+
router.get('/totalBlocks', async (ctx) => (ctx.body = await chain.totalBlocks));
|
|
106
|
+
router.get('/nativeCalls', async (ctx) => (ctx.body = await chain.nativeCalls));
|
|
107
|
+
router.get('/lastBlock', async (ctx) => (ctx.body = await chain.lastBlock));
|
|
108
|
+
router.get('/poolTransactions', async (ctx) => (ctx.body = await globalThis.transactionPoolStore.get()));
|
|
109
|
+
router.get('/transactionsInPool', async (ctx) => (ctx.body = await globalThis.transactionPoolStore.length()));
|
|
110
|
+
router.get('/transactionPoolSize', async (ctx) => (ctx.body = await globalThis.transactionPoolStore.size()));
|
|
111
|
+
router.get('/participating', (ctx) => (ctx.body = chain.participating));
|
|
112
|
+
router.get('/participate', async (ctx) => {
|
|
113
|
+
if (remote)
|
|
114
|
+
ctx.body = await chain.participate(ctx.query.address);
|
|
115
|
+
else
|
|
116
|
+
ctx.status = 405;
|
|
117
|
+
});
|
|
118
|
+
router.get('/deployContract', async (ctx) => {
|
|
119
|
+
try {
|
|
120
|
+
const tx = await chain.deployContract(ctx.query.contract, ctx.query.transaction);
|
|
121
|
+
await tx.wait();
|
|
122
|
+
delete tx.wait;
|
|
123
|
+
ctx.body = JSON.stringify(tx);
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
ctx.body = error.mesage;
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
router.get('/createContractAddress', async (ctx) => {
|
|
130
|
+
try {
|
|
131
|
+
const address = await chain.createContractAddress(ctx.query.owner, ctx.query.code, ctx.query.params);
|
|
132
|
+
ctx.body = address;
|
|
133
|
+
}
|
|
134
|
+
catch (error) { }
|
|
135
|
+
});
|
|
136
|
+
router.get('/blockHashMap', async (ctx) => (ctx.body = chain.blockHashMap));
|
|
137
|
+
router.get('/bootstrap', async (ctx) => {
|
|
138
|
+
ctx.body = (await shared.bootstrap()).map((value) => Array.from(value.toString()));
|
|
139
|
+
});
|
|
140
|
+
// todo finish ...
|
|
141
|
+
api.use(cors({ origin: '*' }));
|
|
142
|
+
api.use(router.routes());
|
|
143
|
+
api.listen(port);
|
|
144
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const networkStats: (chain: any, networkVersion: any) => Promise<{
|
|
2
|
+
version: any;
|
|
3
|
+
peers: any;
|
|
4
|
+
accounts: any;
|
|
5
|
+
accountsHolding: number;
|
|
6
|
+
accountsHoldingAmount: string;
|
|
7
|
+
topHolders: any[];
|
|
8
|
+
}>;
|
|
9
|
+
declare const _default: {
|
|
10
|
+
networkStats: (chain: any, networkVersion: any) => Promise<{
|
|
11
|
+
version: any;
|
|
12
|
+
peers: any;
|
|
13
|
+
accounts: any;
|
|
14
|
+
accountsHolding: number;
|
|
15
|
+
accountsHoldingAmount: string;
|
|
16
|
+
topHolders: any[];
|
|
17
|
+
}>;
|
|
18
|
+
bootstrap: () => Promise<any>;
|
|
19
|
+
};
|
|
20
|
+
export default _default;
|
package/exports/shared.js
CHANGED
|
@@ -1,39 +1,38 @@
|
|
|
1
|
-
import {formatUnits, BigNumber} from '@leofcoin/utils'
|
|
2
|
-
|
|
1
|
+
import { formatUnits, BigNumber } from '@leofcoin/utils';
|
|
3
2
|
export const networkStats = async (chain, networkVersion) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
let accountsHolding = 0;
|
|
4
|
+
let accountsHoldingAmount = BigNumber.from(0);
|
|
5
|
+
let topHolders = [];
|
|
6
|
+
const balances = Object.entries(await chain.balances)
|
|
7
|
+
.map(([holder, amount]) => {
|
|
8
|
+
amount = BigNumber.from(amount);
|
|
9
|
+
return { holder, amount };
|
|
11
10
|
})
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
.sort((a, b) => formatUnits(b.amount.sub(a.amount)));
|
|
13
|
+
for (let { holder, amount } of balances) {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
if (amount.gt(0)) {
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
accountsHoldingAmount = accountsHoldingAmount.add(amount);
|
|
18
|
+
accountsHolding += 1;
|
|
19
|
+
// @ts-ignore
|
|
20
|
+
topHolders.length < 100 && topHolders.push({ holder, amount: formatUnits(amount) });
|
|
21
|
+
}
|
|
19
22
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
23
|
+
return {
|
|
24
|
+
version: networkVersion,
|
|
25
|
+
peers: globalThis.peernet.peers.map(([id, peer]) => id),
|
|
26
|
+
accounts: await globalThis.accountsStore.length(),
|
|
27
|
+
accountsHolding,
|
|
28
|
+
accountsHoldingAmount: formatUnits(accountsHoldingAmount).toString(),
|
|
29
|
+
topHolders
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
32
|
const bootstrap = async () => {
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
|
|
33
|
+
return globalThis.blockStore.values();
|
|
34
|
+
};
|
|
36
35
|
export default {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
36
|
+
networkStats,
|
|
37
|
+
bootstrap
|
|
38
|
+
};
|
package/exports/ws.d.ts
ADDED
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.2",
|
|
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
package/exports/api.md
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
#### [selectAccount(address: `string`)](https://remote.leofcoin.org/select-account?address=)
|
|
2
|
-
`address`: desired address
|
|
3
|
-
> set default account to given address
|
|
4
|
-
```js
|
|
5
|
-
await client.selectAccount(address)
|
|
6
|
-
```
|
|
7
|
-
<br>
|
|
8
|
-
|
|
9
|
-
#### [getBlock(index: `number`)](https://remote.leofcoin.org/getblock?index=0)
|
|
10
|
-
`index`: index of the block to fetch<br>
|
|
11
|
-
```js
|
|
12
|
-
await client.getBlock(10)
|
|
13
|
-
```
|
|
14
|
-
<br>
|
|
15
|
-
|
|
16
|
-
#### [blocks(amount)](https://remote.leofcoin.org/blocks)
|
|
17
|
-
`amount`: the amount to slice
|
|
18
|
-
```js
|
|
19
|
-
await client.blocks(-25)
|
|
20
|
-
```
|
|
21
|
-
<br>
|
|
22
|
-
|
|
23
|
-
#### createTransactionFrom(from: `string`, to: `string`, method: `string`, parameters: `array`, nonce: `number` | `undefined`)
|
|
24
|
-
|
|
25
|
-
`from`:<br>
|
|
26
|
-
`to`: <br>
|
|
27
|
-
`method`: <br>
|
|
28
|
-
`parameters`: <br>
|
|
29
|
-
`nonce`: <br>
|
|
30
|
-
```js
|
|
31
|
-
await client.createTransactionFrom(from, to, method, parameters, nonce)
|
|
32
|
-
```
|
|
33
|
-
<br>
|
|
34
|
-
|
|
35
|
-
#### [lookup(name: `string`)](https://remote.leofcoin.org/lookup?name=ArtOnlineContractFactory)
|
|
36
|
-
`name`: name of the contract to lookup the address and owner of
|
|
37
|
-
```js
|
|
38
|
-
await client.lookup('contractName')
|
|
39
|
-
```
|
|
40
|
-
<br>
|
|
41
|
-
|
|
42
|
-
#### participate(address: `string`)
|
|
43
|
-
`address`: <br>
|
|
44
|
-
|
|
45
|
-
```js
|
|
46
|
-
await client.participate(address)
|
|
47
|
-
```
|
|
48
|
-
<br>
|
|
49
|
-
|
|
50
|
-
#### staticCall(contract: `string`, method: `string`, params: `array`)
|
|
51
|
-
`contract`: contract address todo the call on
|
|
52
|
-
`method`: method/function to call
|
|
53
|
-
`params`: array containing params needed to call the desired method
|
|
54
|
-
```js
|
|
55
|
-
await client.staticCall(contract, method, params)
|
|
56
|
-
```
|
|
57
|
-
<br>
|
|
58
|
-
|
|
59
|
-
#### createContractAddress(owner: `string`, code: `string`, params: `array`)
|
|
60
|
-
`owner`: address of the deployer<br>
|
|
61
|
-
`code`: contract as a string<br>
|
|
62
|
-
`params`: contract constructor params<br>
|
|
63
|
-
|
|
64
|
-
```js
|
|
65
|
-
const address = await client.createContractAddress(owner, code, params)
|
|
66
|
-
```
|
|
67
|
-
<br>
|
|
68
|
-
|
|
69
|
-
#### deployContract(code: `string`, params: `array`)
|
|
70
|
-
`code`: contract as a string<br>
|
|
71
|
-
`params`: contract constructor params<br>
|
|
72
|
-
|
|
73
|
-
```js
|
|
74
|
-
const tx = await client.deployContract(code, params)
|
|
75
|
-
```
|
|
76
|
-
<br>
|
|
77
|
-
|
|
78
|
-
#### [accounts()](https://remote.leofcoin.org/accounts)
|
|
79
|
-
```js
|
|
80
|
-
await client.accounts()
|
|
81
|
-
```
|
|
82
|
-
<br>
|
|
83
|
-
|
|
84
|
-
#### [hasTransactionToHandle()](https://remote.leofcoin.org/hasTransactionToHandle)
|
|
85
|
-
```js
|
|
86
|
-
await client.hasTransactionToHandle()
|
|
87
|
-
```
|
|
88
|
-
<br>
|
|
89
|
-
|
|
90
|
-
#### [balances()](https://remote.leofcoin.org/balances)
|
|
91
|
-
> returns all balances
|
|
92
|
-
```js
|
|
93
|
-
await client.balances()
|
|
94
|
-
```
|
|
95
|
-
<br>
|
|
96
|
-
|
|
97
|
-
#### [balancOf(address: `string`, format: `boolean`)](https://remote.leofcoin.org/balanceOf?address=YTqxKshWH4Qo7KprGYxQVCNYutedaE6YGoUdUPnUdFUVBPrTzgsrP&format=true)
|
|
98
|
-
`address`: The address to check<br>
|
|
99
|
-
`format`: Wether or not to format<br>
|
|
100
|
-
> returns the balance of given address as BigNumber or string (when format is true)
|
|
101
|
-
```js
|
|
102
|
-
await client.balanceOf(address, true)
|
|
103
|
-
```
|
|
104
|
-
<br>
|
|
105
|
-
|
|
106
|
-
#### [getNonce(address: `string`)](https://remote.leofcoin.org/getNonce?address=YTqxKshWH4Qo7KprGYxQVCNYutedaE6YGoUdUPnUdFUVBPrTzgsrP)
|
|
107
|
-
`address`: The address to check<br>
|
|
108
|
-
`format`: Wether or not to format<br>
|
|
109
|
-
> returns the balance of given address as BigNumber or string (when format is true)
|
|
110
|
-
```js
|
|
111
|
-
await client.getNonce(address)
|
|
112
|
-
```
|
|
113
|
-
<br>
|
|
114
|
-
|
|
115
|
-
#### [selectedAccount()](https://remote.leofcoin.org/selectedAccount)
|
|
116
|
-
```js
|
|
117
|
-
await client.selectedAccount()
|
|
118
|
-
```
|
|
119
|
-
<br>
|
|
120
|
-
|
|
121
|
-
#### [peerId()](https://remote.leofcoin.org/peerId)
|
|
122
|
-
```js
|
|
123
|
-
await client.peerId()
|
|
124
|
-
```
|
|
125
|
-
<br>
|
|
126
|
-
|
|
127
|
-
#### [peers()](https://remote.leofcoin.org/peers)
|
|
128
|
-
```js
|
|
129
|
-
await client.peers()
|
|
130
|
-
```
|
|
131
|
-
<br>
|
|
132
|
-
|
|
133
|
-
#### [validators()](https://remote.leofcoin.org/validators)
|
|
134
|
-
```js
|
|
135
|
-
await client.validators()
|
|
136
|
-
```
|
|
137
|
-
<br>
|
|
138
|
-
|
|
139
|
-
#### [nativeBurns()](https://remote.leofcoin.org/nativeBurns)
|
|
140
|
-
```js
|
|
141
|
-
await client.nativeBurns()
|
|
142
|
-
```
|
|
143
|
-
<br>
|
|
144
|
-
|
|
145
|
-
#### [contracts()](https://remote.leofcoin.org/contracts)
|
|
146
|
-
```js
|
|
147
|
-
await client.contracts()
|
|
148
|
-
```
|
|
149
|
-
<br>
|
|
150
|
-
|
|
151
|
-
#### [nativeMints()](https://remote.leofcoin.org/nativeMints)
|
|
152
|
-
```js
|
|
153
|
-
await client.nativeMints()
|
|
154
|
-
```
|
|
155
|
-
<br>
|
|
156
|
-
|
|
157
|
-
#### [nativeToken()](https://remote.leofcoin.org/nativeToken)
|
|
158
|
-
```js
|
|
159
|
-
await client.nativeToken()
|
|
160
|
-
```
|
|
161
|
-
<br>
|
|
162
|
-
|
|
163
|
-
#### [nativeTransfers()](https://remote.leofcoin.org/nativeTransfers)
|
|
164
|
-
```js
|
|
165
|
-
await client. nativeTransfers()
|
|
166
|
-
```
|
|
167
|
-
<br>
|
|
168
|
-
|
|
169
|
-
#### [totalSize()](https://remote.leofcoin.org/totalSize)
|
|
170
|
-
```js
|
|
171
|
-
await client.totalSize()
|
|
172
|
-
```
|
|
173
|
-
<br>
|
|
174
|
-
|
|
175
|
-
#### [totalTransactions()](https://remote.leofcoin.org/totalTransactions)
|
|
176
|
-
```js
|
|
177
|
-
await client.totalTransactions()
|
|
178
|
-
```
|
|
179
|
-
<br>
|
|
180
|
-
|
|
181
|
-
#### [poolTransactions()](https://remote.leofcoin.org/poolTransactions)
|
|
182
|
-
```js
|
|
183
|
-
await client.poolTransactions()
|
|
184
|
-
```
|
|
185
|
-
<br>
|
|
186
|
-
|
|
187
|
-
#### [transactionsInPool()](https://remote.leofcoin.org/transactionsInPool)
|
|
188
|
-
```js
|
|
189
|
-
await client.transactionsInPool()
|
|
190
|
-
```
|
|
191
|
-
<br>
|
|
192
|
-
|
|
193
|
-
#### [transactionPoolSize()](https://remote.leofcoin.org/transactionPoolSize)
|
|
194
|
-
```js
|
|
195
|
-
await client.transactionPoolSize()
|
|
196
|
-
```
|
|
197
|
-
<br>
|
|
198
|
-
|
|
199
|
-
#### [totalBlocks()](https://remote.leofcoin.org/totalBlocks)
|
|
200
|
-
```js
|
|
201
|
-
await client.totalBlocks()
|
|
202
|
-
```
|
|
203
|
-
<br>
|
|
204
|
-
|
|
205
|
-
#### [nativeCalls()](https://remote.leofcoin.org/nativeCalls)
|
|
206
|
-
```js
|
|
207
|
-
await client.nativeCalls()
|
|
208
|
-
```
|
|
209
|
-
<br>
|
|
210
|
-
|
|
211
|
-
#### [participating()](https://remote.leofcoin.org/participating)
|
|
212
|
-
```js
|
|
213
|
-
await client.participating()
|
|
214
|
-
```
|
|
215
|
-
<br>
|
|
216
|
-
|
|
217
|
-
#### [network()](https://remote.leofcoin.org/network)
|
|
218
|
-
```js
|
|
219
|
-
await client.network()
|
|
220
|
-
```
|
|
221
|
-
<br>
|
|
222
|
-
|
|
223
|
-
#### [networkStats()](https://remote.leofcoin.org/networkStats)
|
|
224
|
-
```js
|
|
225
|
-
await client.networkStats()
|
|
226
|
-
```
|
|
227
|
-
<br>
|
|
228
|
-
|
|
229
|
-
#### [networkStats()](https://remote.leofcoin.org/networkStats)
|
|
230
|
-
```js
|
|
231
|
-
await client.networkStats()
|
|
232
|
-
```
|
|
233
|
-
<br>
|
|
234
|
-
|
|
235
|
-
#### [lastBlock()](https://remote.leofcoin.org/lastBlock)
|
|
236
|
-
```js
|
|
237
|
-
await client.lastBlock()
|
|
238
|
-
```
|
|
239
|
-
<br>
|
|
240
|
-
|
|
241
|
-
#### [blockHashMap()](https://remote.leofcoin.org/blockHashMap)
|
|
242
|
-
```js
|
|
243
|
-
await client.blockHashMap()
|
|
244
|
-
```
|
|
245
|
-
<br>
|
|
246
|
-
|
|
247
|
-
#### [bootstrap()](https://remote.leofcoin.org/bootstrap)
|
|
248
|
-
```js
|
|
249
|
-
await client.bootstrap()
|
|
250
|
-
```
|
|
251
|
-
<br>
|