@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,108 @@
1
+ export default class NameService {
2
+ /**
3
+ * string
4
+ */
5
+ #name = 'ArtOnlineNameService'
6
+ /**
7
+ * string
8
+ */
9
+ #owner
10
+ /**
11
+ * number
12
+ */
13
+ #price = 0
14
+ /**
15
+ * Object => string
16
+ */
17
+ #registry = {}
18
+
19
+ /**
20
+ * => string
21
+ */
22
+ #currency
23
+
24
+ get name() {
25
+ return this.#name
26
+ }
27
+
28
+ get registry() {
29
+ return {...this.#registry}
30
+ }
31
+
32
+ get state() {
33
+
34
+ }
35
+
36
+ // TODO: control with contract
37
+ constructor(factoryAddress, currency, validatorAddress, price, state) {
38
+ if (state) {
39
+ this.#owner = state.owner
40
+ this.#registry = state.registry
41
+ this.#currency = state.currency
42
+ this.#price = state.price
43
+ } else {
44
+ this.#owner = msg.sender
45
+ this.#price = price
46
+ this.#registry['ArtOnlineContractFactory'] = {
47
+ owner: msg.sender,
48
+ address: factoryAddress
49
+ }
50
+
51
+ this.#registry['ArtOnlineToken'] = {
52
+ owner: msg.sender,
53
+ address: currency
54
+ }
55
+
56
+ this.#registry['ArtOnlineValidators'] = {
57
+ owner: msg.sender,
58
+ address: validatorAddress
59
+ }
60
+
61
+ this.#currency = currency
62
+ }
63
+ }
64
+
65
+ changeOwner(owner) {
66
+ if (msg.sender !== this.#owner) throw new Error('no owner')
67
+ this.#owner = owner
68
+ }
69
+
70
+ changePrice(price) {
71
+ if (msg.sender !== this.#owner) throw new Error('no owner')
72
+ this.#price = price
73
+ }
74
+
75
+ changeCurrency(currency) {
76
+ if (msg.sender !== this.#owner) throw new Error('no owner')
77
+ this.#currency = currency
78
+ }
79
+
80
+ async purchaseName(name, address) {
81
+ const balance = await msg.call(this.#currency, 'balanceOf', [msg.sender])
82
+ if (balance < this.#price) throw new Error('price exceeds balance')
83
+ try {
84
+ await msg.call(this.#currency, 'transfer', [msg.sender, this.#owner, this.#price])
85
+ } catch (e) {
86
+ throw e
87
+ }
88
+
89
+ this.#registry[name] = {
90
+ owner: msg.sender,
91
+ address
92
+ }
93
+ }
94
+
95
+ lookup(name) {
96
+ return this.#registry[name]
97
+ }
98
+
99
+ transferOwnership(name, to) {
100
+ if (msg.sender !== this.#registry.owner) throw new Error('not a owner')
101
+ this.#registry[name].owner = to
102
+ }
103
+
104
+ changeAddress(name, address) {
105
+ if (msg.sender !== this.#registry.owner) throw new Error('not a owner')
106
+ this.#registry[name].address = address
107
+ }
108
+ }
@@ -0,0 +1,7 @@
1
+ import Token from './../standards/token.js'
2
+
3
+ export default class ArtOnline extends Token {
4
+ constructor(state) {
5
+ super('ArtOnline', 'ART', 18, state)
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ import Token from './../standards/token.js'
2
+
3
+ export default class Power extends Token {
4
+ constructor(state) {
5
+ super('Power', 'PWR', 18, state)
6
+ }
7
+ }
@@ -0,0 +1,12 @@
1
+ import Proxy from './../../standards/Proxy.js'
2
+
3
+ export default class FactoryProxy extends Proxy {
4
+ /**
5
+ * string
6
+ */
7
+ #name = 'ArtOnlineContractFactoryProxy'
8
+
9
+ constructor(proxyManager, state) {
10
+ super(proxyManager, state)
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ import Proxy from './../../standards/Proxy.js'
2
+
3
+ export default class NameServiceProxy extends Proxy {
4
+ /**
5
+ * string
6
+ */
7
+ #name = 'ArtOnlineNameServiceProxy'
8
+
9
+ constructor(proxyManager, state) {
10
+ super(proxyManager, state)
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ import Proxy from './../../standards/Proxy.js'
2
+
3
+ export default class NativeTokenProxy extends Proxy {
4
+ /**
5
+ * string
6
+ */
7
+ #name = 'ArtOnlineNativeTokenProxy'
8
+
9
+ constructor(proxyManager, state) {
10
+ super(proxyManager, state)
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ import Proxy from './../../standards/Proxy.js'
2
+
3
+ export default class ValidatorsProxy extends Proxy {
4
+ /**
5
+ * string
6
+ */
7
+ #name = 'ArtOnlineValidatorsProxy'
8
+
9
+ constructor(proxyManager, state) {
10
+ super(proxyManager, state)
11
+ }
12
+ }
@@ -0,0 +1,12 @@
1
+ import Proxy from './../../standards/Proxy.js'
2
+
3
+ export default class VotingProxy extends Proxy {
4
+ /**
5
+ * string
6
+ */
7
+ #name = 'ArtOnlineVotingProxy'
8
+
9
+ constructor(proxyManager, state) {
10
+ super(proxyManager, state)
11
+ }
12
+ }
@@ -0,0 +1,7 @@
1
+ import ProxyManager from './../standards/proxyManager.js'
2
+
3
+ export default class ArtOnlineProxyManager extends ProxyManager {
4
+ constructor(state) {
5
+ super('ArtOnlineProxyManager', state)
6
+ }
7
+ }
@@ -0,0 +1,119 @@
1
+ export default class Validators {
2
+ /**
3
+ * string
4
+ */
5
+ #name = 'ArtOnlineValidators'
6
+ /**
7
+ * uint
8
+ */
9
+ #totalValidators = 0
10
+ /**
11
+ * Object => string(address) => Object
12
+ */
13
+ #validators = {}
14
+
15
+ #owner
16
+
17
+ #currency
18
+
19
+ #minimumBalance
20
+
21
+ get state() {
22
+ return {
23
+ owner: this.#owner,
24
+ minimumBalance: this.#minimumBalance,
25
+ currency: this.#currency,
26
+ totalValidators: this.#totalValidators,
27
+ validators: this.#validators
28
+ }
29
+ }
30
+
31
+ constructor(tokenAddress, state) {
32
+ if (state) {
33
+ this.#owner = state.owner
34
+ this.#minimumBalance = state.minimumBalance
35
+ this.#currency = state.currency
36
+
37
+ this.#totalValidators = state.totalValidators
38
+ this.#validators = state.validators
39
+ } else {
40
+ this.#owner = msg.sender
41
+ this.#minimumBalance = 50000
42
+ this.#currency = tokenAddress
43
+
44
+ this.#totalValidators += 1
45
+ this.#validators[msg.sender] = {
46
+ firstSeen: new Date().getTime(),
47
+ active: true
48
+ }
49
+ }
50
+
51
+ }
52
+
53
+ get name() {
54
+ return this.#name
55
+ }
56
+
57
+ get owner() {
58
+ return this.#owner
59
+ }
60
+
61
+ get currency() {
62
+ return this.#currency
63
+ }
64
+
65
+ get validators() {
66
+ return {...this.#validators}
67
+ }
68
+
69
+ get totalValidators() {
70
+ return this.#totalValidators
71
+ }
72
+
73
+ get minimumBalance() {
74
+ return this.#minimumBalance
75
+ }
76
+
77
+ changeOwner(owner) {
78
+ if (msg.sender !== this.#owner) throw new Error('not an owner')
79
+ }
80
+
81
+ changeCurrency(currency) {
82
+ if (msg.sender !== this.#owner) throw new Error('not an owner')
83
+ this.#currency = currency
84
+ }
85
+
86
+ has(validator) {
87
+ return Boolean(this.#validators[validator] !== undefined)
88
+ }
89
+
90
+ async addValidator(validator) {
91
+ if (this.has(validator)) throw new Error('already a validator')
92
+ const balance = await msg.staticCall(this.currency, 'balanceOf', [msg.sender])
93
+
94
+ if (balance < this.minimumBalance) throw new Error(`balance to low! got: ${balance} need: ${this.#minimumBalance}`)
95
+
96
+ this.#totalValidators += 1
97
+ this.#validators[validator] = {
98
+ firstSeen: new Date().getTime(),
99
+ active: true
100
+ }
101
+ }
102
+
103
+ removeValidator(validator) {
104
+ if (!this.has(validator)) throw new Error('validator not found')
105
+
106
+ this.#totalValidators -= 1
107
+ delete this.#validators[validator]
108
+ }
109
+
110
+ async updateValidator(validator, active) {
111
+ if (!this.has(validator)) throw new Error('validator not found')
112
+ const balance = await msg.staticCall(this.currency, 'balanceOf', [msg.sender])
113
+ if (balance < this.minimumBalance && this.#validators[validator].active) this.#validators[validator].active = false
114
+
115
+ if (balance < this.minimumBalance) throw new Error(`balance to low! got: ${balance} need: ${this.#minimumBalance}`)
116
+
117
+ this.#validators[validator].active = active
118
+ }
119
+ }
@@ -0,0 +1,3 @@
1
+ export default {
2
+ deployment: 0.000001
3
+ }
package/src/lib.js ADDED
@@ -0,0 +1,67 @@
1
+ import ContractMessage from './messages/contract'
2
+ import TransactionMessage from './messages/transaction'
3
+ import BlockMessage from './messages/block'
4
+ import BWMessage from './messages/bw'
5
+ import BWRequestMessage from './messages/bw-request'
6
+ import bs58 from '@vandeurenglenn/base58'
7
+ import bytecodes from './bytecodes.json'
8
+ import addresses from './addresses.json'
9
+
10
+ const { contractFactory, nativeToken, nameService, validators } = addresses
11
+
12
+ const contractFactoryMessage = new Uint8Array(bytecodes.contractFactory.split(','))
13
+ const nativeTokenMessage = new Uint8Array(bytecodes.nativeToken.split(','))
14
+
15
+ const nameServiceMessage = new Uint8Array(bytecodes.nameService.split(','))
16
+ const validatorsMessage = new Uint8Array(bytecodes.validators.split(','))
17
+
18
+ const calculateFee = transaction => {
19
+ // excluded from fees
20
+ if (transaction.decoded.to === validators) return 0
21
+ // fee per gb
22
+ let fee = transaction.encoded.length
23
+ fee = fee / 1024
24
+ fee = fee / 1000000
25
+ const parts = String(fee).split('.')
26
+ let decimals = 0
27
+ if (parts[1]) {
28
+ const potentional = parts[1].split('e')
29
+ parts[1] = potentional[0]
30
+ decimals = Number(potentional[1].replace(/\-|\+/g, '')) + Number(potentional[0].length)
31
+ }
32
+
33
+ return Number.parseFloat(fee.toString()).toFixed(decimals)
34
+ }
35
+
36
+ const calculateTransactionFee = transaction => {
37
+ transaction = new TransactionMessage(transaction)
38
+ return calculateFee(transaction)
39
+ }
40
+
41
+ const calculateReward = (validators, fees) => {
42
+ validators = Object.keys(validators).reduce((set, key) => {
43
+ if (validators[key].active) set.push({
44
+ address: key,
45
+ reward: 0
46
+ })
47
+
48
+ }, [])
49
+ }
50
+
51
+ export default {
52
+ nativeToken,
53
+ nameService,
54
+ contractFactory,
55
+ validators,
56
+ contractFactoryMessage,
57
+ nativeTokenMessage,
58
+ nameServiceMessage,
59
+ validatorsMessage,
60
+ TransactionMessage,
61
+ ContractMessage,
62
+ BlockMessage,
63
+ BWMessage,
64
+ BWRequestMessage,
65
+ calculateFee,
66
+ calculateTransactionFee
67
+ }
package/src/machine.js ADDED
@@ -0,0 +1,130 @@
1
+ import vm from 'vm'
2
+ import ContractMessage from './messages/contract'
3
+ import TransactionMessage from './messages/transaction'
4
+ import lib from './lib'
5
+ import { info, subinfo } from './utils/utils'
6
+ // import State from './state'
7
+
8
+ export default class Machine {
9
+ #contracts = {}
10
+ #nonces = {}
11
+ constructor() {
12
+ return this.#init()
13
+ }
14
+
15
+ #createMessage(sender = peernet.id) {
16
+ return {
17
+ sender,
18
+ call: this.execute,
19
+ staticCall: this.get.bind(this)
20
+ }
21
+ }
22
+
23
+ async #init() {
24
+ // return
25
+ try {
26
+ let contracts = [
27
+ contractStore.get(lib.contractFactory),
28
+ contractStore.get(lib.nativeToken),
29
+ contractStore.get(lib.validators),
30
+ contractStore.get(lib.nameService)
31
+ ]
32
+
33
+ contracts = await Promise.all(contracts)
34
+ for (const contract of contracts) {
35
+ const message = new ContractMessage(new Uint8Array(contract.buffer, contract.buffer.byteOffset, contract.buffer.byteLength))
36
+ await this.#runContract(message)
37
+ }
38
+ } catch (e) {
39
+ console.log(e);
40
+ }
41
+ // const transactions = await transactionStore.get()
42
+ // console.log({transactions});
43
+ // for (const key of Object.keys(transactions)) {
44
+ // const message = new TransactionMessage(transactions[key])
45
+ // console.log({message});
46
+ // const {from, to, method, params} = message.decoded
47
+ // globalThis.msg = this.#createMessage(from)
48
+ //
49
+ // console.log({from, to, method, params});
50
+ // await this.execute(to, method, params)
51
+ // }
52
+ return this
53
+ }
54
+
55
+ async #runContract(contractMessage) {
56
+ const params = contractMessage.decoded.constructorParameters
57
+ try {
58
+
59
+ const func = new Function(new TextDecoder().decode(contractMessage.decoded.contract))
60
+ const Contract = func()
61
+
62
+ globalThis.msg = this.#createMessage(contractMessage.decoded.creator)
63
+ // globalThis.msg = {sender: contractMessage.decoded.creator}
64
+ this.#contracts[contractMessage.hash] = new Contract(...params)
65
+ info(`loaded contract: ${contractMessage.hash}`);
66
+ subinfo(`size: ${Math.round((contractMessage.encoded.length / 1024) * 100) / 100} kb`);
67
+ } catch (e) {
68
+ console.log(e);
69
+ console.warn(`removing contract ${contractMessage.hash}`);
70
+ await contractStore.delete(contractMessage.hash, contractMessage.encoded)
71
+ }
72
+ }
73
+
74
+ /**
75
+ * @params {ContractMessage} - contractMessage
76
+ */
77
+ async addContract(contractMessage) {
78
+ if (!await contractStore.has(contractMessage.hash)) {
79
+ await contractStore.put(contractMessage.hash, contractMessage.encoded)
80
+ await this.#runContract(contractMessage)
81
+ return contractMessage.hash
82
+ }
83
+ throw new Error('duplicate contract')
84
+ }
85
+
86
+ async execute(contract, method, params) {
87
+ try {
88
+ let result
89
+ // don't execute the method on a proxy
90
+ if (this.#contracts[contract].fallback) {
91
+ result = this.#contracts[contract].fallback(method, params)
92
+ } else {
93
+ result = await this.#contracts[contract][method](...params)
94
+ }
95
+
96
+ // this.#state.put(result)
97
+ return result
98
+ } catch (e) {
99
+ throw e
100
+ }
101
+ }
102
+
103
+ addJob(contract, method, params, from, nonce) {
104
+ if (!this.#nonces[from]) this.#nonces[from] = nonce
105
+ if (nonce === this.#nonces[from] + 1) return this.#contracts[contract][method](...params)
106
+ // return setTimeout(() => {
107
+ // return this.addJob(contract, method, params, from, nonce)
108
+ // }, 50)
109
+ }
110
+
111
+ get(contract, method, params) {
112
+ let result
113
+ if (params?.length > 0) {
114
+ result = this.#contracts[contract][method](...params)
115
+ } else {
116
+ result = this.#contracts[contract][method]
117
+ }
118
+ return result
119
+ }
120
+
121
+ async delete(hash) {
122
+ return contractStore.delete(hash)
123
+ }
124
+
125
+ async deleteAll() {
126
+ let hashes = await contractStore.get()
127
+ hashes = Object.keys(hashes).map(hash => this.delete(hash))
128
+ return Promise.all(hashes)
129
+ }
130
+ }
@@ -0,0 +1,14 @@
1
+ import protons from 'protons'
2
+ import proto from './../protos/block.proto.js'
3
+ import CodecFormat from './../../node_modules/@leofcoin/peernet/src/codec/codec-format-interface'
4
+
5
+ export default class BlockMessage extends CodecFormat {
6
+ get keys() {
7
+ return ['index', 'previousHash', 'timestamp', 'reward', 'fees', 'transactions', 'validators']
8
+ }
9
+
10
+ constructor(buffer) {
11
+ const name = 'block-message'
12
+ super(buffer, protons(proto).BlockMessage, {name})
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ import protons from 'protons'
2
+ import proto from './../protos/bw-request.proto.js'
3
+ import CodecFormat from './../../node_modules/@leofcoin/peernet/src/codec/codec-format-interface'
4
+
5
+ export default class BWRequestMessage extends CodecFormat {
6
+ get keys() {
7
+ return []
8
+ }
9
+
10
+ constructor(buffer) {
11
+ const name = 'bw-request-message'
12
+ super(buffer, protons(proto).BWRequestMessage, {name})
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ import protons from 'protons'
2
+ import proto from './../protos/bw.proto.js'
3
+ import CodecFormat from './../../node_modules/@leofcoin/peernet/src/codec/codec-format-interface'
4
+
5
+ export default class BWMessage extends CodecFormat {
6
+ get keys() {
7
+ return ['up', 'down']
8
+ }
9
+
10
+ constructor(buffer) {
11
+ const name = 'bw-message'
12
+ super(buffer, protons(proto).BWMessage, {name})
13
+ }
14
+ }
@@ -0,0 +1,13 @@
1
+ import protons from 'protons'
2
+ import proto from './../protos/contract.proto.js'
3
+ import CodecFormat from './../../node_modules/@leofcoin/peernet/src/codec/codec-format-interface'
4
+
5
+ export default class ContractMessage extends CodecFormat {
6
+ get keys() {
7
+ return ['creator', 'contract', 'constructorParameters']
8
+ }
9
+
10
+ constructor(buffer) {
11
+ super(buffer, protons(proto).ContractMessage, {name: 'contract-message'})
12
+ }
13
+ }
@@ -0,0 +1,14 @@
1
+ import protons from 'protons'
2
+ import proto from './../protos/last-block-request.proto.js'
3
+ import CodecFormat from './../../node_modules/@leofcoin/peernet/src/codec/codec-format-interface'
4
+
5
+ export default class LastBlockRequestMessage extends CodecFormat {
6
+ get keys() {
7
+ return []
8
+ }
9
+
10
+ constructor(buffer) {
11
+ const name = 'last-block-request-message'
12
+ super(buffer, protons(proto).LastBlockRequestMessage, {name})
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ import protons from 'protons'
2
+ import proto from './../protos/last-block.proto.js'
3
+ import CodecFormat from './../../node_modules/@leofcoin/peernet/src/codec/codec-format-interface'
4
+
5
+ export default class LastBlockMessage extends CodecFormat {
6
+ get keys() {
7
+ return ['hash', 'index']
8
+ }
9
+
10
+ constructor(buffer) {
11
+ const name = 'last-block-message'
12
+ super(buffer, protons(proto).LastBlockMessage, {name})
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ import protons from 'protons'
2
+ import proto from './../protos/transaction.proto.js'
3
+ import CodecFormat from './../../node_modules/@leofcoin/peernet/src/codec/codec-format-interface'
4
+
5
+ export default class TransactionMessage extends CodecFormat {
6
+ get keys() {
7
+ return ['timestamp', 'from', 'to', 'nonce', 'method', 'params']
8
+ }
9
+
10
+ constructor(buffer) {
11
+ const name = 'transaction-message'
12
+ super(buffer, protons(proto).TransactionMessage, {name})
13
+ }
14
+ }
package/src/node.js ADDED
@@ -0,0 +1,55 @@
1
+ // import config from './config/config'
2
+ import Peernet from '@leofcoin/peernet'
3
+ import lib from './lib'
4
+ const { ContractMessage, TransactionMessage, BlockMessage, BWMessage, BWRequestMessage } = lib
5
+
6
+ export default class Node {
7
+ constructor() {
8
+ return this._init()
9
+ }
10
+
11
+ async _init(config = {
12
+ network: 'leofcoin',
13
+ root: '.artonline',
14
+ networkName: 'leofcoin:olivia',
15
+ networkVersion: 'v0.1.0'
16
+ }) {
17
+ globalThis.Peernet ? await new globalThis.Peernet(config) : await new Peernet(config)
18
+
19
+ await peernet.addProto('contract-message', ContractMessage)
20
+ await peernet.addProto('transaction-message', TransactionMessage)
21
+ await peernet.addProto('block-message', BlockMessage)
22
+ await peernet.addProto('bw-message', BWMessage)
23
+ await peernet.addProto('bw-request-message', BWRequestMessage)
24
+
25
+ await peernet.addCodec('contract-message', {
26
+ codec: parseInt('636d', 16),
27
+ hashAlg: 'keccak-256'
28
+ })
29
+ await peernet.addCodec('transaction-message', {
30
+ codec: parseInt('746d', 16),
31
+ hashAlg: 'keccak-256'
32
+ })
33
+
34
+ await peernet.addCodec('block-message', {
35
+ codec: parseInt('626d', 16),
36
+ hashAlg: 'keccak-256'
37
+ })
38
+
39
+ await peernet.addCodec('bw-message', {
40
+ codec: parseInt('62776d', 16),
41
+ hashAlg: 'keccak-256'
42
+ })
43
+
44
+ await peernet.addCodec('bw-request-message', {
45
+ codec: parseInt('6277726d', 16),
46
+ hashAlg: 'keccak-256'
47
+ })
48
+
49
+ await peernet.addStore('contract', 'art', '.ArtOnline', false)
50
+ await peernet.addStore('transactionPool', 'art', '.ArtOnline', false)
51
+ return this
52
+ // this.config = await config()
53
+ }
54
+
55
+ }