@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,58 @@
1
+
2
+
3
+ (async () => {
4
+ const {promisify} = require('util')
5
+ const read = promisify(require('fs').readFile)
6
+ const write = promisify(require('fs').writeFile)
7
+ const {join} = require('path')
8
+ const createMessage = async (src, params = []) => {
9
+ const contract = await read(src)
10
+ return chain.createContractMessage(peernet.id, new TextEncoder().encode(`return ${contract.toString().replace(/export{([A-Z])\w+ as default}/g, '')}`), params)
11
+ }
12
+ const Chain = require('./../dist/chain');
13
+ const Node = require('./../dist/node');
14
+ const node = await new Node()
15
+ const chain = await new Chain()
16
+ const factory = await createMessage('./dist/contracts/factory.js')
17
+
18
+ if (!await contractStore.has(factory.hash)) {
19
+ await contractStore.put(factory.hash, factory.encoded)
20
+ }
21
+
22
+ const nativeToken = await createMessage('./dist/contracts/nativeToken.js')
23
+ if (!await contractStore.has(nativeToken.hash)) {
24
+ await contractStore.put(nativeToken.hash, nativeToken.encoded)
25
+ }
26
+
27
+
28
+ const validators = await createMessage('./dist/contracts/validators.js', [nativeToken.hash])
29
+
30
+ if (!await contractStore.has(validators.hash)) {
31
+ await contractStore.put(validators.hash, validators.encoded)
32
+ }
33
+
34
+
35
+ const nameService = await createMessage('./dist/contracts/nameService.js', [factory.hash, nativeToken.hash, validators.hash, BigNumber.from('1000')])
36
+
37
+ if (!await contractStore.has(nameService.hash)) {
38
+ await contractStore.put(nameService.hash, nameService.encoded)
39
+ }
40
+ const addresses = {
41
+ contractFactory: factory.hash,
42
+ nativeToken: nativeToken.hash,
43
+ nameService: nameService.hash,
44
+ validators: validators.hash
45
+ }
46
+
47
+
48
+
49
+ const bytecodes = {
50
+ contractFactory: await factory.toString(),
51
+ nativeToken: await nativeToken.toString(),
52
+ nameService: await nameService.toString(),
53
+ validators: await validators.toString()
54
+ }
55
+
56
+ await write(join(process.cwd(), 'src/addresses.json'), JSON.stringify(addresses, null, '\t'))
57
+ await write(join(process.cwd(), 'src/bytecodes.json'), JSON.stringify(bytecodes, null, '\t'))
58
+ })()
package/test/index.js ADDED
@@ -0,0 +1,3 @@
1
+ // require('./contracts/token')
2
+ // require('./create-genesis')
3
+ require('./chain')
@@ -0,0 +1,167 @@
1
+ const path = require('path');
2
+ const webpack = require('webpack');
3
+ module.exports = [{
4
+ entry: './src/chain.js',
5
+ plugins: [
6
+ // Work around for Buffer is undefined:
7
+ // https://github.com/webpack/changelog-v5/issues/10
8
+ new webpack.ProvidePlugin({
9
+ Buffer: ['buffer', 'Buffer'],
10
+ }),
11
+ new webpack.ProvidePlugin({
12
+ process: 'process/browser',
13
+ })
14
+ ],
15
+ optimization: {
16
+ minimize: false
17
+ },
18
+ resolve: {
19
+ // extensions: [ '.ts', '.js' ],
20
+ fallback: {
21
+ vm: require.resolve("vm-browserify"),
22
+ // "stream": require.resolve("stream-browserify"),
23
+ "buffer": require.resolve("buffer")
24
+ // fs: false,
25
+ // "path": require.resolve("path-browserify"),
26
+ // "util": require.resolve("util/"),
27
+ // "assert": require.resolve("assert/"),
28
+ }
29
+ },
30
+ output: {
31
+ library: {
32
+ type: 'module'
33
+ },
34
+ filename: 'chain.browser.js',
35
+ path: path.resolve(__dirname, 'dist'),
36
+ },
37
+ experiments: {
38
+ outputModule: true
39
+ }
40
+ }, {
41
+ entry: './src/chain.js',
42
+ plugins: [
43
+ // Work around for Buffer is undefined:
44
+ // https://github.com/webpack/changelog-v5/issues/10
45
+ new webpack.ProvidePlugin({
46
+ Buffer: ['buffer', 'Buffer'],
47
+ }),
48
+ new webpack.ProvidePlugin({
49
+ process: 'process/browser',
50
+ })
51
+ ],
52
+ optimization: {
53
+ minimize: true
54
+ },
55
+ resolve: {
56
+ // extensions: [ '.ts', '.js' ],
57
+ fallback: {
58
+ vm: require.resolve("vm-browserify"),
59
+ // "stream": require.resolve("stream-browserify"),
60
+ "buffer": require.resolve("buffer")
61
+ // fs: false,
62
+ // "path": require.resolve("path-browserify"),
63
+ // "util": require.resolve("util/"),
64
+ // "assert": require.resolve("assert/"),
65
+ }
66
+ },
67
+ output: {
68
+ library: {
69
+ type: 'module'
70
+ },
71
+ filename: 'chain.browser.min.js',
72
+ path: path.resolve(__dirname, 'dist'),
73
+ },
74
+ experiments: {
75
+ outputModule: true
76
+ }
77
+ }, {
78
+ entry: './src/node.js',
79
+ plugins: [
80
+ // Work around for Buffer is undefined:
81
+ // https://github.com/webpack/changelog-v5/issues/10
82
+ // new webpack.ProvidePlugin({
83
+ // Buffer: ['buffer', 'Buffer'],
84
+ // }),
85
+ new webpack.ProvidePlugin({
86
+ process: 'process/browser',
87
+ }),
88
+
89
+ new webpack.ProvidePlugin({
90
+ WRTC_IMPORT: `globalThis.wrtc = {
91
+ RTCPeerConnection,
92
+ RTCSessionDescription,
93
+ RTCIceCandidate
94
+ }`
95
+ })
96
+ ],
97
+ optimization: {
98
+ minimize: false
99
+ },
100
+ resolve: {
101
+ // extensions: [ '.ts', '.js' ],
102
+ fallback: {
103
+ // "stream": require.resolve("stream-browserify"),
104
+ // "buffer": require.resolve("buffer"),
105
+ // fs: false,
106
+ // "path": require.resolve("path-browserify"),
107
+ // "util": require.resolve("util/"),
108
+ // "assert": require.resolve("assert/"),
109
+
110
+ }
111
+ },
112
+ output: {
113
+ library: {
114
+ type: 'module'
115
+ },
116
+ filename: 'node.browser.js',
117
+ path: path.resolve(__dirname, 'dist'),
118
+ },
119
+ experiments: {
120
+ outputModule: true
121
+ }
122
+ }, {
123
+ entry: './src/node.js',
124
+ plugins: [
125
+ // Work around for Buffer is undefined:
126
+ // https://github.com/webpack/changelog-v5/issues/10
127
+ // new webpack.ProvidePlugin({
128
+ // Buffer: ['buffer', 'Buffer'],
129
+ // }),
130
+ new webpack.ProvidePlugin({
131
+ process: 'process/browser',
132
+ }),
133
+
134
+ new webpack.ProvidePlugin({
135
+ WRTC_IMPORT: `globalThis.wrtc = {
136
+ RTCPeerConnection,
137
+ RTCSessionDescription,
138
+ RTCIceCandidate
139
+ }`
140
+ })
141
+ ],
142
+ optimization: {
143
+ minimize: true
144
+ },
145
+ resolve: {
146
+ // extensions: [ '.ts', '.js' ],
147
+ fallback: {
148
+ // "stream": require.resolve("stream-browserify"),
149
+ // "buffer": require.resolve("buffer"),
150
+ // fs: false,
151
+ // "path": require.resolve("path-browserify"),
152
+ // "util": require.resolve("util/"),
153
+ // "assert": require.resolve("assert/"),
154
+
155
+ }
156
+ },
157
+ output: {
158
+ library: {
159
+ type: 'module'
160
+ },
161
+ filename: 'node.browser.min.js',
162
+ path: path.resolve(__dirname, 'dist'),
163
+ },
164
+ experiments: {
165
+ outputModule: true
166
+ }
167
+ }];