@leofcoin/chain 1.0.4

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 (82) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/LICENSE +88 -0
  3. package/README.md +4 -0
  4. package/_node.js +1 -0
  5. package/chain.js +1468 -0
  6. package/demo/index.html +18 -0
  7. package/dist/browser/peernet.js +101516 -0
  8. package/dist/chain.browser.js +19879 -0
  9. package/dist/chain.browser.js.tmp-browserify-65536332430764332457 +0 -0
  10. package/dist/chain.browser.js.tmp-browserify-77283953363424018335 +0 -0
  11. package/dist/chain.browser.min.js +2 -0
  12. package/dist/chain.browser.min.js.LICENSE.txt +10 -0
  13. package/dist/chain.js +1468 -0
  14. package/dist/contracts/factory.js +1 -0
  15. package/dist/contracts/nameService.js +1 -0
  16. package/dist/contracts/nativeToken.js +1 -0
  17. package/dist/contracts/validators.js +1 -0
  18. package/dist/lib.browser.js +16966 -0
  19. package/dist/native.js +1 -0
  20. package/dist/node.browser.js +68961 -0
  21. package/dist/node.browser.min.js +2 -0
  22. package/dist/node.browser.min.js.LICENSE.txt +12 -0
  23. package/dist/node.js +1 -0
  24. package/dist/standards/token.js +1 -0
  25. package/dist/token/native.js +1 -0
  26. package/dist/token.js +1 -0
  27. package/examples/contracts/token.js +7 -0
  28. package/lib.js +1 -0
  29. package/package.json +46 -0
  30. package/plugins/bundle.js +18 -0
  31. package/rollup.config.js +151 -0
  32. package/src/addresses.json +6 -0
  33. package/src/apis/token.lfcc +17 -0
  34. package/src/bytecodes.json +6 -0
  35. package/src/chain.js +593 -0
  36. package/src/config/config.js +15 -0
  37. package/src/config/main.js +4 -0
  38. package/src/config/protocol.js +5 -0
  39. package/src/contracts/factory.js +59 -0
  40. package/src/contracts/nameService.js +108 -0
  41. package/src/contracts/nativeToken.js +7 -0
  42. package/src/contracts/powerToken.js +7 -0
  43. package/src/contracts/proxies/factoryProxy.js +12 -0
  44. package/src/contracts/proxies/nameServiceProxy.js +12 -0
  45. package/src/contracts/proxies/nativeTokenProxy.js +12 -0
  46. package/src/contracts/proxies/validatorsProxy.js +12 -0
  47. package/src/contracts/proxies/votingProxy.js +12 -0
  48. package/src/contracts/proxyManager.js +7 -0
  49. package/src/contracts/validators.js +119 -0
  50. package/src/fee/config.js +3 -0
  51. package/src/lib.js +67 -0
  52. package/src/machine.js +130 -0
  53. package/src/messages/block.js +14 -0
  54. package/src/messages/bw-request.js +14 -0
  55. package/src/messages/bw.js +14 -0
  56. package/src/messages/contract.js +13 -0
  57. package/src/messages/last-block-request.js +14 -0
  58. package/src/messages/last-block.js +14 -0
  59. package/src/messages/transaction.js +14 -0
  60. package/src/node.js +55 -0
  61. package/src/protos/block.proto.js +26 -0
  62. package/src/protos/bw-request.proto.js +5 -0
  63. package/src/protos/bw.proto.js +7 -0
  64. package/src/protos/contract.proto.js +7 -0
  65. package/src/protos/last-block-request.proto.js +5 -0
  66. package/src/protos/last-block.proto.js +7 -0
  67. package/src/protos/transaction.proto.js +11 -0
  68. package/src/standards/Proxy.js +42 -0
  69. package/src/standards/Voting.js +3 -0
  70. package/src/standards/initializer.js +10 -0
  71. package/src/standards/proxyManager.js +66 -0
  72. package/src/standards/roles.js +65 -0
  73. package/src/standards/token.js +137 -0
  74. package/src/state.js +26 -0
  75. package/src/transactions/validator.js +29 -0
  76. package/src/typer.js +19 -0
  77. package/src/utils/utils.js +16 -0
  78. package/test/chain.js +119 -0
  79. package/test/contracts/token.js +40 -0
  80. package/test/create-genesis.js +58 -0
  81. package/test/index.js +3 -0
  82. package/webpack.config.js +167 -0
@@ -0,0 +1,26 @@
1
+ export default `
2
+ message ValidatorMessage {
3
+ required string address = 1;
4
+ required string reward = 2;
5
+ }
6
+
7
+ message Transaction {
8
+ required string hash = 1;
9
+ required uint64 timestamp = 2;
10
+ required string from = 3;
11
+ required string to = 4;
12
+ required uint64 nonce = 5;
13
+ required string method = 6;
14
+ repeated string params = 7;
15
+ }
16
+
17
+ message BlockMessage {
18
+ required uint64 index = 1;
19
+ required string previousHash = 3;
20
+ required uint64 timestamp = 4;
21
+ required uint64 reward = 5;
22
+ required string fees = 6;
23
+ repeated Transaction transactions = 7;
24
+ repeated ValidatorMessage validators = 8;
25
+ }
26
+ `
@@ -0,0 +1,5 @@
1
+ export default `
2
+
3
+ message BWRequestMessage {
4
+ }
5
+ `
@@ -0,0 +1,7 @@
1
+ export default `
2
+
3
+ message BWMessage {
4
+ required uint64 up = 1;
5
+ required uint64 down = 2;
6
+ }
7
+ `
@@ -0,0 +1,7 @@
1
+ export default `
2
+ message ContractMessage {
3
+ required string creator = 1;
4
+ required bytes contract = 2;
5
+ repeated string constructorParameters = 3;
6
+ }
7
+ `
@@ -0,0 +1,5 @@
1
+ export default `
2
+
3
+ message LastBlockRequestMessage {
4
+ }
5
+ `
@@ -0,0 +1,7 @@
1
+ export default `
2
+
3
+ message LastBlockMessage {
4
+ required string hash = 1;
5
+ required uint64 index = 2;
6
+ }
7
+ `
@@ -0,0 +1,11 @@
1
+ export default `
2
+
3
+ message TransactionMessage {
4
+ required uint64 timestamp = 1;
5
+ required string from = 2;
6
+ required string to = 3;
7
+ required uint64 nonce = 4;
8
+ required string method = 5;
9
+ repeated string params = 6;
10
+ }
11
+ `
@@ -0,0 +1,42 @@
1
+ import Roles from './roles.js'
2
+
3
+ export default class Proxy extends Roles {
4
+ #proxyManager
5
+ #implementation
6
+
7
+ constructor(proxyManager, state) {
8
+ super(state?.roles)
9
+ if (state) {
10
+ this.#proxyManager = state.proxyManager
11
+ } else {
12
+ this.#proxyManager = proxyManager
13
+ }
14
+ }
15
+
16
+ get state() {
17
+ return {
18
+ ...super.state,
19
+ proxyManager: this.#proxyManager,
20
+ implementation: this.#implementation
21
+ }
22
+ }
23
+
24
+ async setImplementation(address) {
25
+ if (msg.sender !== this.#proxyManager) throw new Error(`not allowed, expected proxy manager`)
26
+
27
+ const state = await stateStore.get(this.#implementation)
28
+ await stateStore.put(address, state)
29
+ stateStore.delete(this.#implementation)
30
+ this.#implementation = address
31
+ }
32
+
33
+ async changeProxyManager(address) {
34
+ if (msg.sender !== this.#proxyManager) throw new Error(`not allowed, expected proxy manager`)
35
+ this.#proxyManager = address
36
+ }
37
+
38
+ fallback(method, params) {
39
+ if (msg.sender === this.proxyManager) return this[method](...params)
40
+ return msg.internalCall(msg.sender, this.#implementation, method, params)
41
+ }
42
+ }
@@ -0,0 +1,3 @@
1
+ export default class ArtOnlineVoting {
2
+
3
+ }
@@ -0,0 +1,10 @@
1
+ export default class Initializer {
2
+ #initialized = false
3
+ constructor() {
4
+ this.#initialized = true
5
+ }
6
+
7
+ get initialized() {
8
+ return this.#initialized
9
+ }
10
+ }
@@ -0,0 +1,66 @@
1
+ import Roles from './roles.js'
2
+
3
+ export default class ProxyManager extends Roles {
4
+ #name
5
+ #proxies = {}
6
+ #manager
7
+
8
+
9
+ constructor(name, state) {
10
+ super(state?.roles)
11
+ this.#name = name
12
+
13
+ if (state) {
14
+ this.#proxies = state.proxies
15
+ this.#manager = state.manager
16
+ } else {
17
+ this.#manager = msg.sender
18
+ }
19
+ }
20
+
21
+ /**
22
+ *
23
+ */
24
+ async #upgradeProxy(proxy, address) {
25
+ await msg.internalCall(this.#manager, proxy, 'setImplementation', [address])
26
+ this.#proxies[proxy] = address
27
+ }
28
+
29
+ /**
30
+ *
31
+ */
32
+ upgradeProxy(proxy, address) {
33
+ if (!this.hasRole(msg.sender, 'MANAGER')) throw new Error('Not allowed, expected MANAGER')
34
+ this.#upgradeProxy(proxy, address)
35
+ }
36
+
37
+ async #changeManager(address) {
38
+ this.#revokeRole(this.#manager, 'MANAGER')
39
+ this.#grantRole(address, 'MANAGER')
40
+ for (const proxy of Object.keys(this.#proxies)) {
41
+ await msg.internalCall(this.#manager, proxy, 'changeProxyManager', [address])
42
+ }
43
+ this.#manager = address
44
+ }
45
+
46
+ changeManager(address) {
47
+ if (!this.hasRole(msg.sender, 'OWNER')) throw new Error('Not allowed, expected OWNER')
48
+ return this.#changeManager(address)
49
+ }
50
+
51
+ get state() {
52
+ return {
53
+ ...super.state,
54
+ proxies: this.proxies,
55
+ manager: this.manager
56
+ }
57
+ }
58
+
59
+ get manager() {
60
+ return this.#manager
61
+ }
62
+
63
+ get proxies() {
64
+ return { ...this.#proxies }
65
+ }
66
+ }
@@ -0,0 +1,65 @@
1
+ export default class Roles {
2
+
3
+ /**
4
+ * Object => Array
5
+ */
6
+ #roles = {
7
+ 'OWNER': [],
8
+ 'MINT': [],
9
+ 'BURN': []
10
+ }
11
+
12
+ constructor(roles) {
13
+ // allow devs to set their own roles but always keep the default ones included
14
+ // also allows roles to be loaded from the stateStore
15
+ // carefull when includin gthe roles make sure to add the owner
16
+ // since no roles are granted by default when using custom roles
17
+ if (roles) {
18
+ if (roles instanceof Object) {
19
+ this.#roles = {...roles, ...this.#roles}
20
+ } else {
21
+ throw new Error(`expected roles to be an object`)
22
+ }
23
+ } else {
24
+ // no roles given so default to the msg sender
25
+ this.#grantRole(msg.sender, 'OWNER')
26
+ }
27
+ }
28
+
29
+ get state() {
30
+ return { roles: this.roles }
31
+ }
32
+
33
+ get roles() {
34
+ return {...this.#roles}
35
+ }
36
+
37
+ hasRole(address, role) {
38
+ return this.#roles[role] ? this.#roles[role].indexOf(address) !== -1 : false
39
+ }
40
+
41
+ #grantRole(address, role) {
42
+ if (this.hasRole(address, role)) throw new Error(`${role} role already granted for ${address}`)
43
+
44
+ this.#roles[role].push(address)
45
+ }
46
+
47
+ #revokeRole(address, role) {
48
+ if (!this.hasRole(address, role)) throw new Error(`${role} role already revoked for ${address}`)
49
+ if (role === 'OWNER' && this.#roles[role].length === 1) throw new Error(`atleast one owner is needed!`)
50
+
51
+ this.#roles[role].splice(this.#roles[role].indexOf(address))
52
+ }
53
+
54
+ grantRole(address, role) {
55
+ if (!this.hasRole(address, 'OWNER')) throw new Error('Not allowed')
56
+
57
+ this.#grantRole(address, role)
58
+ }
59
+
60
+ revokeRole(address, role) {
61
+ if (!this.hasRole(address, 'OWNER')) throw new Error('Not allowed')
62
+
63
+ this.#revokeRole(address, role)
64
+ }
65
+ }
@@ -0,0 +1,137 @@
1
+ import Roles from './roles.js'
2
+
3
+ export default class Token extends Roles {
4
+ /**
5
+ * string
6
+ */
7
+ #name
8
+ /**
9
+ * String
10
+ */
11
+ #symbol
12
+ /**
13
+ * uint
14
+ */
15
+ #holders = 0
16
+ /**
17
+ * Object => Object => uint
18
+ */
19
+ #balances = {}
20
+ /**
21
+ * Object => Object => uint
22
+ */
23
+ #approvals = {}
24
+
25
+ #decimals = 18
26
+
27
+ #totalSupply = BigNumber.from(0)
28
+
29
+ // this.#privateField2 = 1
30
+ constructor(name, symbol, decimals = 18, state) {
31
+ if (!name) throw new Error(`name undefined`)
32
+ if (!symbol) throw new Error(`symbol undefined`)
33
+
34
+ super(state?.roles)
35
+
36
+ this.#name = name
37
+ this.#symbol = symbol
38
+ this.#decimals = decimals
39
+ }
40
+
41
+ // enables snapshotting
42
+ // needs dev attention so nothing breaks after snapshot happens
43
+ // iow everything that is not static needs to be included in the stateObject
44
+ /**
45
+ * @return {Object} {holders, balances, ...}
46
+ */
47
+ get state() {
48
+ return {
49
+ ...super.state,
50
+ holders: this.holders,
51
+ balances: this.balances,
52
+ approvals: { ...this.#approvals },
53
+ totalSupply: this.totalSupply
54
+ }
55
+ }
56
+
57
+ get totalSupply() {
58
+ return this.#totalSupply
59
+ }
60
+
61
+ get name() {
62
+ return this.#name
63
+ }
64
+
65
+ get symbol() {
66
+ return this.#symbol
67
+ }
68
+
69
+ get holders() {
70
+ return this.#holders
71
+ }
72
+
73
+ get balances() {
74
+ return {...this.#balances}
75
+ }
76
+
77
+ mint(to, amount) {
78
+ if (!this.hasRole(msg.sender, 'MINT')) throw new Error('not allowed')
79
+
80
+ this.#totalSupply = this.#totalSupply.add(amount)
81
+ this.#increaseBalance(to, amount)
82
+ }
83
+
84
+ burn(to, amount) {
85
+ if (!this.hasRole(msg.sender, 'BURN')) throw new Error('not allowed')
86
+
87
+ this.#totalSupply = this.#totalSupply.sub(amount)
88
+ this.#decreaseBalance(to, amount)
89
+ }
90
+
91
+ #beforeTransfer(from, to, amount) {
92
+ if (!this.#balances[from] || this.#balances[from] < amount) throw new Error('amount exceeds balance')
93
+ }
94
+
95
+ #updateHolders(address, previousBalance) {
96
+ if (this.#balances[address].toHexString() === '0x00') this.#holders -= 1
97
+ else if (this.#balances[address].toHexString() !== '0x00' && previousBalance.toHexString() === '0x00') this.#holders += 1
98
+ }
99
+
100
+ #increaseBalance(address, amount) {
101
+ if (!this.#balances[address]) this.#balances[address] = BigNumber.from(0)
102
+ const previousBalance = this.#balances[address]
103
+
104
+ this.#balances[address] = this.#balances[address].add(amount)
105
+ this.#updateHolders(address, previousBalance)
106
+ }
107
+
108
+ #decreaseBalance(address, amount) {
109
+ const previousBalance = this.#balances[address]
110
+ this.#balances[address] = this.#balances[address].sub(amount)
111
+ this.#updateHolders(address, previousBalance)
112
+ }
113
+
114
+ balanceOf(address) {
115
+ return this.#balances[address]
116
+ }
117
+
118
+ setApproval(operator, amount) {
119
+ const owner = globalThis.msg.sender
120
+ if (!this.#approvals[owner]) this.#approvals[owner] = {}
121
+ this.#approvals[owner][operator] = amount
122
+ }
123
+
124
+ approved(owner, operator, amount) {
125
+ return this.#approvals[owner][operator] === amount
126
+ }
127
+
128
+ transfer(from, to, amount) {
129
+ // TODO: is BigNumber?
130
+ amount = BigNumber.from(amount)
131
+ this.#beforeTransfer(from, to, amount)
132
+ this.#decreaseBalance(from, amount)
133
+ this.#increaseBalance(to, amount)
134
+ }
135
+
136
+
137
+ }
package/src/state.js ADDED
@@ -0,0 +1,26 @@
1
+ import pako from 'pako'
2
+
3
+ export default class State {
4
+ constructor() {
5
+ // return this.#init()
6
+ }
7
+
8
+ // async #init() {
9
+ // const state = await stateStore.get()
10
+ // for (const [key, value] of Object.entries(state)) {
11
+ //
12
+ // }
13
+ //
14
+ // return this
15
+ // }
16
+
17
+ async put(key, value, isCompressed = false) {
18
+ value = isCompressed ? isCompressed : await pako.deflate(value)
19
+ await stateStore.put(key, value)
20
+ }
21
+
22
+ async get(key) {
23
+ const value = await stateStore.get(key)
24
+ return pako.inflate(value)
25
+ }
26
+ }
@@ -0,0 +1,29 @@
1
+ import hasher from './crypto/hasher'
2
+ import {create} from './crypto/transaction'
3
+
4
+ export default class Validator {
5
+ constructor(address) {
6
+ this._init(address)
7
+ }
8
+
9
+ async _init(address) {
10
+ const valid = await this.isValid(address, this)
11
+ if (!valid) throw new Error('Invalid validator')
12
+ return this
13
+ }
14
+
15
+ async isValid(hash, transaction) {
16
+ return this.validateTransaction(hash, transaction)
17
+ }
18
+
19
+ async validateTransaction(hash, transaction) {
20
+ delete transaction.hash
21
+ transaction = await create(hasher.hash(transaction))
22
+ if (transaction !== hash) throw Error('invalid hash')
23
+ // for (const input of transaction) {
24
+ // input
25
+ // }
26
+ return true
27
+
28
+ }
29
+ }
package/src/typer.js ADDED
@@ -0,0 +1,19 @@
1
+ import {BigNumber} from './utils/utils'
2
+
3
+ const codec = '0x'
4
+
5
+ const isAddress = address => {
6
+ if (!address.startsWith(codec)) return false
7
+ if (address.length !== 64) return false
8
+ }
9
+
10
+ export default {
11
+ isType: (type, value) => {
12
+ type = type.toLowercase()
13
+ if (type === 'string') return typeof(value) === type
14
+ if (type === 'number') return !isNaN(Number(value))
15
+ if (type === 'address') return isAddress(value)
16
+ if (type === 'BigNumber') return BigNumber.isBigNumber(value)
17
+ },
18
+ isAddress
19
+ }
@@ -0,0 +1,16 @@
1
+ // import { promisify } from 'util'
2
+ // import { writeFile, readFile } from 'fs'
3
+ export { BigNumber } from "@ethersproject/bignumber";
4
+ export { formatUnits, parseUnits } from '@ethersproject/units'
5
+ import chalk from 'chalk'
6
+
7
+ const info = text => console.log(chalk.blueBright(text))
8
+
9
+ const subinfo = text => console.log(chalk.magentaBright(text))
10
+
11
+ export {
12
+ info,
13
+ subinfo
14
+ }
15
+ // export const write = promisify(writeFile)
16
+ // export const read = promisify(readFile)
package/test/chain.js ADDED
@@ -0,0 +1,119 @@
1
+
2
+
3
+ (async () => {
4
+ globalThis.DEBUG = true
5
+ const Chain = require('./../dist/chain');
6
+ const Node = require('./../dist/node');
7
+ const node = await new Node()
8
+ const chain = await new Chain()
9
+ let start
10
+ //
11
+ // await chain.deleteAll()
12
+ // return
13
+ // try {
14
+ // const contract = await chain.utils.read('./dist/native.js')
15
+ // const address = await chain.deployContract(peernet.Buffer.from(`return ${contract.toString().replace(/export{([A-Z])\w+ as default}/g, '')}`))
16
+ // console.log(address);
17
+ // } catch (e) {
18
+ // console.log(e);
19
+ // } finally {
20
+ //
21
+ // }
22
+ // '5xdacigaguxg3yjllehp65htk32ha3sztlexxrrhmviobgibz6dt6hkxfu'
23
+
24
+ await chain.participate()
25
+ // let balances = chain.balances
26
+ // console.log({balances});
27
+ // console.log(`balance for ${Object.keys(balances)[0]}:${chain.utils.formatUnits(balances[Object.keys(balances)[0]]).toString()}`);
28
+ // console.log(`balance for ${Object.keys(balances)[1]}:${chain.utils.formatUnits(balances[Object.keys(balances)[1]]).toString()}`);
29
+ const job = async () => {
30
+ setTimeout(async () => {
31
+
32
+ let tx
33
+ try {
34
+ tx = await chain.createTransaction(chain.nativeToken, 'grantRole', [peernet.id, 'MINT'])
35
+ await tx.wait()
36
+
37
+
38
+ } catch (e) {
39
+ console.log(e);
40
+ }
41
+
42
+ try {
43
+ tx = await chain.createTransaction(chain.nativeToken, 'mint', [peernet.id, chain.utils.parseUnits('1000000000').toString()])
44
+ await tx.wait()
45
+ } catch (e) {
46
+ console.log(e);
47
+ }
48
+ let promises = []
49
+ // nonce += 1
50
+ for (let i = 0; i < 10; i++) {
51
+ // contract , method, from, to, amount, (optional) nonce
52
+ promises.push(chain.createTransaction(chain.nativeToken, 'transfer', [peernet.id, '3CzV5vEE3nceXUXe8vTpRz95dBhL8V54zKjAGd8YxjCmdW2J8ZxrYw', chain.utils.parseUnits('100').toString()]))
53
+ }
54
+ promises = await Promise.allSettled(promises)
55
+ console.log({promises});
56
+ promises = await Promise.allSettled(promises.map(({value}) => value.wait()))
57
+ console.log({promises});
58
+ promises.forEach((item, i) => {
59
+ if (item.reason) console.log(item.reason);
60
+ });
61
+
62
+ console.log(promises[1].reason);
63
+ // console.log(promises);
64
+ // await promises[promises.length - 1].value.wait()
65
+ // promises = []
66
+ // for (let i = 0; i < 50; i++) {
67
+ // promises.push(chain.createTransaction(chain.nativeToken, 'transfer', ['0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000001', 100]))
68
+ // }
69
+
70
+ // promises = await Promise.all(promises)
71
+ // await promises[promises.length - 1].wait()
72
+ console.log(`${(new Date().getTime() - start) / 1000} s`);
73
+ // setTimeout(function () {
74
+ // const balances = chain.balances
75
+ // console.log(`balance for ${Object.keys(balances)[0]}:${chain.utils.formatUnits(balances[Object.keys(balances)[0]]).toString()}`);
76
+ // console.log(`balance for ${Object.keys(balances)[1]}:${chain.utils.formatUnits(balances[Object.keys(balances)[1]]).toString()}`);
77
+ //
78
+ // }, 30000);
79
+ // console.log({tx});
80
+ // let result = chain.mint('0x0000000000000000000000000000000000000000', 100)
81
+ // result = chain.transfer('0x0000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000001', 100)
82
+
83
+
84
+ balances = chain.balances
85
+ console.log({balances});
86
+ console.log(`balance for ${Object.keys(balances)[0]}:${chain.utils.formatUnits(balances[Object.keys(balances)[0]]).toString()}`);
87
+ console.log(`balance for ${Object.keys(balances)[1]}:${chain.utils.formatUnits(balances[Object.keys(balances)[1]]).toString()}`);
88
+
89
+ // setTimeout(async () => {
90
+ promises = []
91
+ console.log('run');
92
+ // nonce += 1
93
+ for (let i = 0; i < 100; i++) {
94
+ // contract , method, from, to, amount, (optional) nonce
95
+ promises.push(chain.createTransaction(chain.nativeToken, 'transfer', [peernet.id, '3CzV5vEE3nceXUXe8vTpRz95dBhL8V54zKjAGd8YxjCmdW2J8ZxrYw', chain.utils.parseUnits('100').toString()]))
96
+ // nonce += 1
97
+ }
98
+ promises = await Promise.allSettled(promises)
99
+ promises = await Promise.allSettled(promises.map(({value}) => value.wait()))
100
+ balances = chain.balances
101
+ console.log({balances});
102
+ console.log(`balance for ${Object.keys(balances)[0]}:${chain.utils.formatUnits(balances[Object.keys(balances)[0]]).toString()}`);
103
+ console.log(`balance for ${Object.keys(balances)[1]}:${chain.utils.formatUnits(balances[Object.keys(balances)[1]]).toString()}`);
104
+ // }, 10000);
105
+
106
+ // job()
107
+ }, 5000);
108
+ }
109
+
110
+ setTimeout(function () {
111
+ start = new Date().getTime()
112
+ console.log(peernet.connections);
113
+ }, 10000);
114
+ try {
115
+ job()
116
+ } catch (e) {
117
+ console.warn(e);
118
+ }
119
+ })()
@@ -0,0 +1,40 @@
1
+ const test = require('tape')
2
+
3
+ const Token = require('./../../dist/token');
4
+
5
+ class TestToken extends Token {
6
+ constructor() {
7
+ super('token', 'TKN')
8
+ }
9
+ }
10
+
11
+
12
+ // const token = new TestToken()
13
+
14
+ test("can't access private", tape => {
15
+ tape.plan(3)
16
+ token.holders = 5
17
+ token.balances[0] = 100
18
+ token.symbol = 'TTT'
19
+ console.log(token.symbol);
20
+ tape.ok(token.symbol === 'TKN', 'symbol')
21
+ tape.ok(Object.keys(token.balances).length === 0, 'balances')
22
+ tape.ok(token.holders === 0, 'holders')
23
+ })
24
+
25
+ // test("transfer", tape => {
26
+ // tape.plan(1)
27
+ // console.log(token.balances);
28
+ // try {
29
+ // token.transfer('0', '1', 100)
30
+ // } catch (e) {
31
+ // console.log(e);
32
+ // } finally {
33
+ //
34
+ // }
35
+ // console.log(token.balances);
36
+ //
37
+ // tape.ok(token.balances[1] === 100)
38
+ // })
39
+
40
+ // console.log(new NativeToken());