@leofcoin/chain 1.4.21 → 1.4.23

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.
Files changed (92) hide show
  1. package/LICENSE +88 -88
  2. package/README.md +4 -4
  3. package/exports/chain.js +1071 -0
  4. package/exports/node.js +23 -0
  5. package/exports/typings/chain.d.ts +83 -0
  6. package/exports/typings/config/config.d.ts +1 -0
  7. package/exports/typings/config/main.d.ts +5 -0
  8. package/exports/typings/config/protocol.d.ts +6 -0
  9. package/exports/typings/contract.d.ts +29 -0
  10. package/exports/typings/fee/config.d.ts +4 -0
  11. package/exports/typings/machine.d.ts +26 -0
  12. package/exports/typings/node.d.ts +9 -0
  13. package/exports/typings/protocol.d.ts +4 -0
  14. package/exports/typings/state.d.ts +5 -0
  15. package/exports/typings/transaction.d.ts +47 -0
  16. package/exports/typings/typer.d.ts +6 -0
  17. package/package.json +77 -75
  18. package/CHANGELOG.md +0 -14
  19. package/block-worker.js +0 -1
  20. package/demo/865.browser.js +0 -10
  21. package/demo/chain.browser.js +0 -66842
  22. package/demo/generate-account.browser.js +0 -50
  23. package/demo/index.html +0 -25
  24. package/demo/messages.browser.js +0 -328
  25. package/demo/multi-wallet.browser.js +0 -15
  26. package/demo/node.browser.js +0 -9858
  27. package/demo/pako.browser.js +0 -6900
  28. package/demo/peernet-swarm.browser.js +0 -839
  29. package/demo/storage.browser.js +0 -3724
  30. package/demo/workers/865.js +0 -10
  31. package/demo/workers/block-worker.js +0 -13175
  32. package/demo/workers/machine-worker.js +0 -13385
  33. package/demo/workers/pool-worker.js +0 -8503
  34. package/demo/workers/transaction-worker.js +0 -8495
  35. package/demo/wrtc.browser.js +0 -28
  36. package/dist/browser/workers/865.js +0 -10
  37. package/dist/browser/workers/block-worker.js +0 -9460
  38. package/dist/browser/workers/machine-worker.js +0 -9670
  39. package/dist/browser/workers/pool-worker.js +0 -4608
  40. package/dist/browser/workers/transaction-worker.js +0 -4600
  41. package/dist/chain.js +0 -10128
  42. package/dist/client-80bc8156.js +0 -491
  43. package/dist/commonjs-7fe3c381.js +0 -270
  44. package/dist/contracts/factory.js +0 -1
  45. package/dist/contracts/name-service.js +0 -1
  46. package/dist/contracts/native-token.js +0 -1
  47. package/dist/contracts/validators.js +0 -1
  48. package/dist/generate-account-445db122.js +0 -46
  49. package/dist/index-57f93805.js +0 -718
  50. package/dist/messages-bce1b91d-81af3b00.js +0 -315
  51. package/dist/module/chain.js +0 -10091
  52. package/dist/module/client-8031ec88.js +0 -489
  53. package/dist/module/commonjs-9005d5c0.js +0 -268
  54. package/dist/module/generate-account-489552b6.js +0 -44
  55. package/dist/module/index-ac2285c4.js +0 -688
  56. package/dist/module/messages-bce1b91d-eaf75d83.js +0 -302
  57. package/dist/module/node.js +0 -7049
  58. package/dist/module/workers/block-worker.js +0 -94
  59. package/dist/module/workers/machine-worker.js +0 -304
  60. package/dist/module/workers/pool-worker.js +0 -55
  61. package/dist/module/workers/transaction-worker.js +0 -47
  62. package/dist/node.js +0 -7061
  63. package/dist/standards/token.js +0 -1
  64. package/dist/workers/machine-worker.js +0 -1
  65. package/dist/workers/pool-worker.js +0 -1
  66. package/dist/workers/transaction-worker.js +0 -1
  67. package/examples/contracts/token.js +0 -7
  68. package/plugins/bundle.js +0 -18
  69. package/rollup.config.js +0 -15
  70. package/src/chain.ts +0 -710
  71. package/src/config/config.js +0 -14
  72. package/src/config/main.js +0 -4
  73. package/src/config/protocol.js +0 -5
  74. package/src/contract.js +0 -52
  75. package/src/fee/config.js +0 -3
  76. package/src/machine.js +0 -215
  77. package/src/node.ts +0 -24
  78. package/src/protocol.js +0 -4
  79. package/src/state.js +0 -31
  80. package/src/transaction.ts +0 -182
  81. package/src/type.index.d.ts +0 -21
  82. package/src/typer.js +0 -19
  83. package/test/chain.js +0 -150
  84. package/test/contracts/token.js +0 -40
  85. package/test/create-genesis.js +0 -66
  86. package/test/index.js +0 -1
  87. package/tsconfig.json +0 -17
  88. package/workers/block-worker.js +0 -40
  89. package/workers/machine-worker.js +0 -219
  90. package/workers/pool-worker.js +0 -28
  91. package/workers/transaction-worker.js +0 -20
  92. package/workers/workers.js +0 -9
@@ -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() {
8
+ return this._init();
9
+ }
10
+ async _init(config = {
11
+ network: 'leofcoin:peach',
12
+ networkName: 'leofcoin:peach',
13
+ networkVersion: 'peach',
14
+ stars: networks.leofcoin.peach.stars
15
+ }) {
16
+ globalThis.Peernet ? await new globalThis.Peernet(config) : await new Peernet(config);
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,5 @@
1
+ declare namespace _default {
2
+ const datadir: string;
3
+ const configPath: string;
4
+ }
5
+ export default _default;
@@ -0,0 +1,6 @@
1
+ declare namespace _default {
2
+ namespace block {
3
+ const size: number;
4
+ }
5
+ }
6
+ export default _default;
@@ -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,4 @@
1
+ declare namespace _default {
2
+ const deployment: number;
3
+ }
4
+ export default _default;
@@ -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,9 @@
1
+ export default class Node {
2
+ constructor();
3
+ _init(config?: {
4
+ network: string;
5
+ networkName: string;
6
+ networkVersion: string;
7
+ stars: any;
8
+ }): Promise<this>;
9
+ }
@@ -0,0 +1,4 @@
1
+ export default class Protocol {
2
+ limit: number;
3
+ transactionLimit: number;
4
+ }
@@ -0,0 +1,5 @@
1
+ export default class State {
2
+ put(key: any, value: any, isCompressed?: boolean): Promise<void>;
3
+ get(key: any, isCompressed?: boolean): Promise<any>;
4
+ updateState(block: any): void;
5
+ }
@@ -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
+ }
@@ -0,0 +1,6 @@
1
+ declare namespace _default {
2
+ export function isType(type: any, value: any): any;
3
+ export { isAddress };
4
+ }
5
+ export default _default;
6
+ declare function isAddress(address: any): boolean;
package/package.json CHANGED
@@ -1,75 +1,77 @@
1
- {
2
- "name": "@leofcoin/chain",
3
- "version": "1.4.21",
4
- "description": "Official javascript implementation",
5
- "main": "./dist/node.js",
6
- "module": "./dist/chain.esm",
7
- "exports": {
8
- "./node": "./exports/node.js",
9
- "./chain": "./exports/chain.js"
10
- },
11
- "types": "./exports/types/chain.d.ts",
12
- "type": "module",
13
- "scripts": {
14
- "np": "np",
15
- "lint": "eslint src --fix",
16
- "c": "rollup -c",
17
- "w": "rollup -c -w",
18
- "docs": "sh ./node_modules/.bin/esdoc src/chain.js",
19
- "workers": "cp ./../workers/src/** ./workers",
20
- "build": "npm run c",
21
- "demo": "jsproject --serve ./demo --port 5478 --open demo",
22
- "test": "node --openssl-legacy-provider test",
23
- "pack": "webpack"
24
- },
25
- "np": {
26
- "yarn": false,
27
- "contents": "."
28
- },
29
- "browserslist": "> 0.5%, last 2 versions, not dead",
30
- "keywords": [],
31
- "author": "",
32
- "license": "MIT",
33
- "devDependencies": {
34
- "@rollup/plugin-json": "^6.0.0",
35
- "@rollup/plugin-typescript": "^11.0.0",
36
- "@types/bs58check": "^2.1.0",
37
- "@types/pako": "^2.0.0",
38
- "@types/randombytes": "^2.0.0",
39
- "@types/varint": "^6.0.1",
40
- "@vandeurenglenn/debug": "^1.0.0",
41
- "eslint": "^8.28.0",
42
- "eslint-plugin-unicorn": "^45.0.0",
43
- "open": "^8.4.0",
44
- "rollup": "^3.12.0",
45
- "tape": "^5.5.2",
46
- "tslib": "^2.4.1"
47
- },
48
- "dependencies": {
49
- "@leofcoin/addresses": "^1.0.4",
50
- "@leofcoin/codec-format-interface": "^1.6.4",
51
- "@leofcoin/lib": "^1.0.11",
52
- "@leofcoin/messages": "^1.2.0",
53
- "@leofcoin/multi-wallet": "^2.1.1",
54
- "@leofcoin/networks": "^1.0.0",
55
- "@leofcoin/peernet": "^1.0.0",
56
- "@leofcoin/storage": "^3.0.6",
57
- "@leofcoin/utils": "^1.1.4",
58
- "@leofcoin/workers": "^1.3.5",
59
- "@vandeurenglenn/base32": "^1.1.0",
60
- "@vandeurenglenn/easy-worker": "^1.0.2",
61
- "@vandeurenglenn/queue": "^1.0.0",
62
- "chalk": "^4.0.0",
63
- "pako": "^2.0.4"
64
- },
65
- "eslintConfig": {
66
- "env": {
67
- "es2022": true
68
- },
69
- "parserOptions": {
70
- "ecmaVersion": "latest",
71
- "sourceType": "module"
72
- },
73
- "extends": "plugin:unicorn/recommended"
74
- }
75
- }
1
+ {
2
+ "name": "@leofcoin/chain",
3
+ "version": "1.4.23",
4
+ "description": "Official javascript implementation",
5
+ "exports": {
6
+ "./node": "./exports/node.js",
7
+ "./chain": "./exports/chain.js"
8
+ },
9
+ "types": "./exports/types/chain.d.ts",
10
+ "type": "module",
11
+ "files": [
12
+ "./exports",
13
+ "LICENSE.txt"
14
+ ],
15
+ "scripts": {
16
+ "np": "np",
17
+ "lint": "eslint src --fix",
18
+ "c": "rollup -c",
19
+ "w": "rollup -c -w",
20
+ "docs": "sh ./node_modules/.bin/esdoc src/chain.js",
21
+ "workers": "cp ./../workers/src/** ./workers",
22
+ "build": "npm run c",
23
+ "demo": "jsproject --serve ./demo --port 5478 --open demo",
24
+ "test": "node --openssl-legacy-provider test",
25
+ "pack": "webpack"
26
+ },
27
+ "np": {
28
+ "yarn": false,
29
+ "contents": "."
30
+ },
31
+ "browserslist": "> 0.5%, last 2 versions, not dead",
32
+ "keywords": [],
33
+ "author": "",
34
+ "license": "MIT",
35
+ "devDependencies": {
36
+ "@rollup/plugin-json": "^6.0.0",
37
+ "@rollup/plugin-typescript": "^11.0.0",
38
+ "@types/bs58check": "^2.1.0",
39
+ "@types/pako": "^2.0.0",
40
+ "@types/randombytes": "^2.0.0",
41
+ "@types/varint": "^6.0.1",
42
+ "@vandeurenglenn/debug": "^1.0.0",
43
+ "eslint": "^8.28.0",
44
+ "eslint-plugin-unicorn": "^45.0.0",
45
+ "open": "^8.4.0",
46
+ "rollup": "^3.12.0",
47
+ "tape": "^5.5.2",
48
+ "tslib": "^2.4.1"
49
+ },
50
+ "dependencies": {
51
+ "@leofcoin/addresses": "^1.0.4",
52
+ "@leofcoin/codec-format-interface": "^1.6.4",
53
+ "@leofcoin/lib": "^1.0.11",
54
+ "@leofcoin/messages": "^1.2.0",
55
+ "@leofcoin/multi-wallet": "^2.1.1",
56
+ "@leofcoin/networks": "^1.0.0",
57
+ "@leofcoin/peernet": "^1.0.0",
58
+ "@leofcoin/storage": "^3.0.6",
59
+ "@leofcoin/utils": "^1.1.4",
60
+ "@leofcoin/workers": "^1.3.5",
61
+ "@vandeurenglenn/base32": "^1.1.0",
62
+ "@vandeurenglenn/easy-worker": "^1.0.2",
63
+ "@vandeurenglenn/queue": "^1.0.0",
64
+ "chalk": "^4.0.0",
65
+ "pako": "^2.0.4"
66
+ },
67
+ "eslintConfig": {
68
+ "env": {
69
+ "es2022": true
70
+ },
71
+ "parserOptions": {
72
+ "ecmaVersion": "latest",
73
+ "sourceType": "module"
74
+ },
75
+ "extends": "plugin:unicorn/recommended"
76
+ }
77
+ }
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/block-worker.js DELETED
@@ -1 +0,0 @@
1
- "use strict";var e=require("@leofcoin/codec-format-interface"),r=require("@ethersproject/bignumber");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("@ethersproject/units"),require("randombytes");var a=s(require("@vandeurenglenn/easy-worker"));class BlockMessage extends e.FormatInterface{get keys(){return["index","previousHash","timestamp","reward","fees","transactions","validators"]}get messageName(){return"BlockMessage"}constructor(e){super(e,"\nmessage ValidatorMessage {\n required string address = 1;\n required string reward = 2;\n}\n\nmessage Transaction {\n required string hash = 1;\n required uint64 timestamp = 2;\n required string from = 3;\n required string to = 4;\n required uint64 nonce = 5;\n required string method = 6;\n repeated string params = 7;\n}\n\nmessage BlockMessage {\n required uint64 index = 1;\n required string previousHash = 3;\n required uint64 timestamp = 4;\n required uint64 reward = 5;\n required string fees = 6;\n repeated Transaction transactions = 7;\n repeated ValidatorMessage validators = 8;\n}\n",{name:"block-message"})}}const n=["Bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],t=new a.default;globalThis.BigNumber=r.BigNumber,globalThis.peernet=globalThis.peernet||{},globalThis.contracts={};const i=async e=>(e=(e=await Promise.all(e.map((e=>new BlockMessage(e))))).sort(((e,r)=>e.decoded.timestamp-r.decoded.timestamp)),e=await Promise.all(e.map((e=>new Promise((async(r,s)=>{const a=e.encoded.length||e.encoded.byteLength;console.log(`loaded block: ${await e.hash} @${e.decoded.index} ${((e,r=2)=>{if(0===e)return"0 Bytes";r<0&&(r=0);const s=Math.floor(Math.log(e)/Math.log(1024));return`${parseFloat((e/Math.pow(1024,s)).toFixed(r))} ${n[s]}`})(a)}`),r(e)}))))));t.onmessage((e=>(async e=>{globalThis.peernet.codecs={"block-message":{codec:parseInt("626d",16),hashAlg:"keccak-256"}},e=await i(e),t.postMessage(e)})(e)));
@@ -1,10 +0,0 @@
1
- (self["webpackChunk_leofcoin_chain"] = self["webpackChunk_leofcoin_chain"] || []).push([[865],{
2
-
3
- /***/ 3865:
4
- /***/ (function() {
5
-
6
- /* (ignored) */
7
-
8
- /***/ })
9
-
10
- }])