@leofcoin/chain 1.4.22 → 1.4.24
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/chain.js +1071 -0
- package/exports/node.js +23 -0
- package/exports/typings/chain.d.ts +83 -0
- package/exports/typings/config/config.d.ts +1 -0
- package/exports/typings/config/main.d.ts +5 -0
- package/exports/typings/config/protocol.d.ts +6 -0
- package/exports/typings/contract.d.ts +29 -0
- package/exports/typings/fee/config.d.ts +4 -0
- package/exports/typings/machine.d.ts +26 -0
- package/exports/typings/node.d.ts +9 -0
- package/exports/typings/protocol.d.ts +4 -0
- package/exports/typings/state.d.ts +5 -0
- package/exports/typings/transaction.d.ts +47 -0
- package/exports/typings/typer.d.ts +6 -0
- package/package.json +12 -6
- package/CHANGELOG.md +0 -14
- package/demo/index.html +0 -25
- package/examples/contracts/token.js +0 -7
- package/plugins/bundle.js +0 -18
- package/src/chain.js +0 -716
- package/src/config/config.js +0 -14
- package/src/config/main.js +0 -4
- package/src/config/protocol.js +0 -5
- package/src/contract.js +0 -52
- package/src/fee/config.js +0 -3
- package/src/machine.js +0 -215
- package/src/node.js +0 -24
- package/src/protocol.js +0 -4
- package/src/state.js +0 -31
- package/src/transaction.js +0 -234
- package/src/type.index.d.ts +0 -21
- package/src/typer.js +0 -19
- package/test/chain.js +0 -120
- package/test/contracts/token.js +0 -40
- package/test/create-genesis.js +0 -66
- package/test/index.js +0 -1
- package/tsconfig.js +0 -15
- package/workers/block-worker.js +0 -40
- package/workers/machine-worker.js +0 -219
- package/workers/pool-worker.js +0 -28
- package/workers/transaction-worker.js +0 -20
- package/workers/workers.js +0 -9
package/exports/node.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Peernet from '@leofcoin/peernet';
|
|
2
|
+
import nodeConfig from '@leofcoin/lib/node-config';
|
|
3
|
+
import networks from '@leofcoin/networks';
|
|
4
|
+
|
|
5
|
+
// import config from './config/config'
|
|
6
|
+
class Node {
|
|
7
|
+
constructor(config, password) {
|
|
8
|
+
return this._init(config, password);
|
|
9
|
+
}
|
|
10
|
+
async _init(config = {
|
|
11
|
+
network: 'leofcoin:peach',
|
|
12
|
+
networkName: 'leofcoin:peach',
|
|
13
|
+
networkVersion: 'peach',
|
|
14
|
+
stars: networks.leofcoin.peach.stars
|
|
15
|
+
}, password) {
|
|
16
|
+
globalThis.Peernet ? await new globalThis.Peernet(config, password) : await new Peernet(config, password);
|
|
17
|
+
await nodeConfig(config);
|
|
18
|
+
return this;
|
|
19
|
+
// this.config = await config()
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { Node as default };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import Contract from './contract.js';
|
|
2
|
+
import { BigNumberish } from '@ethersproject/bignumber';
|
|
3
|
+
export default class Chain extends Contract {
|
|
4
|
+
#private;
|
|
5
|
+
constructor();
|
|
6
|
+
get nativeMints(): number;
|
|
7
|
+
get nativeBurns(): number;
|
|
8
|
+
get nativeTransfers(): number;
|
|
9
|
+
get totalTransactions(): number;
|
|
10
|
+
get nativeCalls(): number;
|
|
11
|
+
get totalSize(): number;
|
|
12
|
+
get lib(): any;
|
|
13
|
+
get lastBlock(): {
|
|
14
|
+
index: number;
|
|
15
|
+
hash: string;
|
|
16
|
+
previousHash: string;
|
|
17
|
+
};
|
|
18
|
+
get nativeToken(): any;
|
|
19
|
+
get validators(): any[];
|
|
20
|
+
get blocks(): any[];
|
|
21
|
+
hasTransactionToHandle(): Promise<boolean>;
|
|
22
|
+
promiseRequests(promises: any): Promise<unknown>;
|
|
23
|
+
getLatestBlock(): Promise<{
|
|
24
|
+
index: number;
|
|
25
|
+
hash: string;
|
|
26
|
+
}>;
|
|
27
|
+
resolveBlock(hash: any): any;
|
|
28
|
+
resolveBlocks(): any;
|
|
29
|
+
participate(address: any): Promise<void>;
|
|
30
|
+
/**
|
|
31
|
+
* every tx done is trough contracts so no need for amount
|
|
32
|
+
* data is undefined when nothing is returned
|
|
33
|
+
* error is thrown on error so undefined data doesn't mean there is an error...
|
|
34
|
+
**/
|
|
35
|
+
sendTransaction(transaction: any): Promise<{
|
|
36
|
+
hash: any;
|
|
37
|
+
data: any;
|
|
38
|
+
fee: string | 0;
|
|
39
|
+
wait: Promise<unknown>;
|
|
40
|
+
message: any;
|
|
41
|
+
}>;
|
|
42
|
+
addContract(contractMessage: any): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param {Address} sender
|
|
46
|
+
* @param {Address} contract
|
|
47
|
+
* @param {String} method
|
|
48
|
+
* @param {Array} parameters
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
internalCall(sender: any, contract: any, method: any, parameters: any): any;
|
|
52
|
+
/**
|
|
53
|
+
*
|
|
54
|
+
* @param {Address} contract
|
|
55
|
+
* @param {String} method
|
|
56
|
+
* @param {Array} parameters
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
call(contract: any, method: any, parameters: any): any;
|
|
60
|
+
staticCall(contract: any, method: any, parameters?: any): any;
|
|
61
|
+
delegate(contract: any, method: any, parameters: any): any;
|
|
62
|
+
staticDelegate(contract: Address, method: string, parameters: []): any;
|
|
63
|
+
mint(to: string, amount: BigNumberish): any;
|
|
64
|
+
transfer(from: string, to: string, amount: BigNumberish): any;
|
|
65
|
+
get balances(): {
|
|
66
|
+
address: BigNumberish;
|
|
67
|
+
};
|
|
68
|
+
get contracts(): any;
|
|
69
|
+
deleteAll(): any;
|
|
70
|
+
/**
|
|
71
|
+
* lookup an address for a registered name using the builtin nameService
|
|
72
|
+
* @check nameService
|
|
73
|
+
*
|
|
74
|
+
* @param {String} - contractName
|
|
75
|
+
* @returns {String} - address
|
|
76
|
+
*
|
|
77
|
+
* @example chain.lookup('myCoolContractName') // qmqsfddfdgfg...
|
|
78
|
+
*/
|
|
79
|
+
lookup(name: any): {
|
|
80
|
+
owner: string;
|
|
81
|
+
address: string;
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @extends {Transaction}
|
|
3
|
+
*/
|
|
4
|
+
export default class Contract extends Transaction {
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {Address} creator
|
|
8
|
+
* @param {String} contract
|
|
9
|
+
* @param {Array} constructorParameters
|
|
10
|
+
* @returns lib.createContractMessage
|
|
11
|
+
*/
|
|
12
|
+
createContractMessage(creator: Address, contract: string, constructorParameters?: any[]): Promise<import("@leofcoin/messages").ContractMessage>;
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param {Address} creator
|
|
16
|
+
* @param {String} contract
|
|
17
|
+
* @param {Array} constructorParameters
|
|
18
|
+
* @returns {Address}
|
|
19
|
+
*/
|
|
20
|
+
createContractAddress(creator: Address, contract: string, constructorParameters?: any[]): Address;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {String} contract
|
|
24
|
+
* @param {Array} parameters
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
deployContract(contract: string, constructorParameters?: any[]): Promise<any>;
|
|
28
|
+
}
|
|
29
|
+
import Transaction from "./transaction.js";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export default class Machine {
|
|
2
|
+
constructor(blocks: any);
|
|
3
|
+
lastBlock: {
|
|
4
|
+
index: number;
|
|
5
|
+
hash: string;
|
|
6
|
+
previousHash: string;
|
|
7
|
+
};
|
|
8
|
+
worker: any;
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param {Address} contract
|
|
12
|
+
* @param {String} method
|
|
13
|
+
* @param {Array} parameters
|
|
14
|
+
* @returns Promise<message>
|
|
15
|
+
*/
|
|
16
|
+
execute(contract: Address, method: string, parameters: any[]): Promise<any>;
|
|
17
|
+
get(contract: any, method: any, parameters: any): Promise<any>;
|
|
18
|
+
has(address: any): Promise<any>;
|
|
19
|
+
delete(hash: any): Promise<any>;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @returns Promise
|
|
23
|
+
*/
|
|
24
|
+
deleteAll(): Promise<any>;
|
|
25
|
+
#private;
|
|
26
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import Protocol from "./protocol.js";
|
|
2
|
+
import { TransactionMessage } from "@leofcoin/messages";
|
|
3
|
+
export default class Transaction extends Protocol {
|
|
4
|
+
#private;
|
|
5
|
+
constructor();
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {Address[]} transactions
|
|
9
|
+
* @returns transactions to include
|
|
10
|
+
*/
|
|
11
|
+
getTransactions(transactions: any): Promise<unknown>;
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {Transaction[]} transactions An array containing Transactions
|
|
15
|
+
* @returns {TransactionMessage}
|
|
16
|
+
*/
|
|
17
|
+
promiseTransactions(transactions: any): Promise<TransactionMessage[]>;
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param {Transaction[]} transactions An array containing Transactions
|
|
21
|
+
* @returns {Object} {transaction.decoded, transaction.hash}
|
|
22
|
+
*/
|
|
23
|
+
promiseTransactionsContent(transactions: any): Promise<any>;
|
|
24
|
+
/**
|
|
25
|
+
* Get amount of transactions by address
|
|
26
|
+
* @param {Address} address The address to get the nonce for
|
|
27
|
+
* @returns {Number} nonce
|
|
28
|
+
*/
|
|
29
|
+
getNonce(address: any): Promise<number>;
|
|
30
|
+
validateNonce(address: any, nonce: any): Promise<void>;
|
|
31
|
+
isTransactionMessage(message: any): boolean;
|
|
32
|
+
createTransaction(transaction: any): Promise<{
|
|
33
|
+
from: any;
|
|
34
|
+
to: any;
|
|
35
|
+
method: any;
|
|
36
|
+
params: any;
|
|
37
|
+
timestamp: any;
|
|
38
|
+
nonce: any;
|
|
39
|
+
}>;
|
|
40
|
+
sendTransaction(message: any): Promise<{
|
|
41
|
+
hash: any;
|
|
42
|
+
data: any;
|
|
43
|
+
fee: string | 0;
|
|
44
|
+
wait: Promise<unknown>;
|
|
45
|
+
message: any;
|
|
46
|
+
}>;
|
|
47
|
+
}
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/chain",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.24",
|
|
4
4
|
"description": "Official javascript implementation",
|
|
5
|
-
"main": "./dist/node.js",
|
|
6
|
-
"module": "./dist/chain.esm",
|
|
7
5
|
"exports": {
|
|
8
|
-
"./node": "./
|
|
9
|
-
"./chain": "./
|
|
6
|
+
"./node": "./exports/node.js",
|
|
7
|
+
"./chain": "./exports/chain.js"
|
|
10
8
|
},
|
|
9
|
+
"types": "./exports/types/chain.d.ts",
|
|
11
10
|
"type": "module",
|
|
11
|
+
"files": [
|
|
12
|
+
"./exports",
|
|
13
|
+
"LICENSE.txt"
|
|
14
|
+
],
|
|
12
15
|
"scripts": {
|
|
13
16
|
"np": "np",
|
|
14
17
|
"lint": "eslint src --fix",
|
|
@@ -16,7 +19,7 @@
|
|
|
16
19
|
"w": "rollup -c -w",
|
|
17
20
|
"docs": "sh ./node_modules/.bin/esdoc src/chain.js",
|
|
18
21
|
"workers": "cp ./../workers/src/** ./workers",
|
|
19
|
-
"build": "npm run c
|
|
22
|
+
"build": "npm run c",
|
|
20
23
|
"demo": "jsproject --serve ./demo --port 5478 --open demo",
|
|
21
24
|
"test": "node --openssl-legacy-provider test",
|
|
22
25
|
"pack": "webpack"
|
|
@@ -30,6 +33,8 @@
|
|
|
30
33
|
"author": "",
|
|
31
34
|
"license": "MIT",
|
|
32
35
|
"devDependencies": {
|
|
36
|
+
"@rollup/plugin-json": "^6.0.0",
|
|
37
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
33
38
|
"@types/bs58check": "^2.1.0",
|
|
34
39
|
"@types/pako": "^2.0.0",
|
|
35
40
|
"@types/randombytes": "^2.0.0",
|
|
@@ -38,6 +43,7 @@
|
|
|
38
43
|
"eslint": "^8.28.0",
|
|
39
44
|
"eslint-plugin-unicorn": "^45.0.0",
|
|
40
45
|
"open": "^8.4.0",
|
|
46
|
+
"rollup": "^3.12.0",
|
|
41
47
|
"tape": "^5.5.2",
|
|
42
48
|
"tslib": "^2.4.1"
|
|
43
49
|
},
|
package/CHANGELOG.md
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# changelog
|
|
2
|
-
------
|
|
3
|
-
|
|
4
|
-
## v1.1.0
|
|
5
|
-
- validators produce blocks
|
|
6
|
-
- syncs blocks with other nodes
|
|
7
|
-
- double contracts throw and are not added (no cost)
|
|
8
|
-
- transactions that fail are ignored (no cost and less resource usage)
|
|
9
|
-
- native contracts that are internally used by the chain (iow no need for a wrapped token)
|
|
10
|
-
- native voting system
|
|
11
|
-
- all native contracts are proxied (less hasle when upgrading a contract)
|
|
12
|
-
- can add/remove validators
|
|
13
|
-
- added stateStore (contracts can be loaded using the state now) (introduces breaking change, devs need to make the state of their contract exposable)
|
|
14
|
-
- added snapshotting (recover from state)
|
package/demo/index.html
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en" dir="ltr">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<title></title>
|
|
6
|
-
</head>
|
|
7
|
-
<body>
|
|
8
|
-
<!-- <script src="./../dist/node.browser.js"></script>
|
|
9
|
-
<script src="./../dist/chain.browser.js"></script> -->
|
|
10
|
-
|
|
11
|
-
<script type="module">
|
|
12
|
-
import LeofcoinNode from './node.browser.js'
|
|
13
|
-
import LeofcoinChain from './chain.browser.js'
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
await new LeofcoinNode()
|
|
17
|
-
globalThis.chain = await new LeofcoinChain()
|
|
18
|
-
} catch (e) {
|
|
19
|
-
console.log(e);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
</script>
|
|
24
|
-
</body>
|
|
25
|
-
</html>
|
package/plugins/bundle.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import rollup from 'rollup'
|
|
2
|
-
|
|
3
|
-
const config = {
|
|
4
|
-
input: ['src/interfaces/token.js'],
|
|
5
|
-
output: {
|
|
6
|
-
dir: 'dist',
|
|
7
|
-
format: 'es'
|
|
8
|
-
},
|
|
9
|
-
plugins: [
|
|
10
|
-
json(),
|
|
11
|
-
strip(),
|
|
12
|
-
terser({
|
|
13
|
-
mangle: true,
|
|
14
|
-
keep_classnames: true
|
|
15
|
-
})
|
|
16
|
-
// resolve({preferBuiltins: false,browser: false, extensions: ['.js', '.mjs', '.node']}),
|
|
17
|
-
]
|
|
18
|
-
}
|