@leofcoin/chain 1.1.4 → 1.1.6

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/dist/chain.js CHANGED
@@ -494,7 +494,7 @@ class Chain {
494
494
  let promises = [];
495
495
  for (const peer of peernet.connections) {
496
496
  if (peer.peerId !== this.id) {
497
- let data = new peernet.protos['peernet-request']({request: 'lastBlock'});
497
+ let data = await new peernet.protos['peernet-request']({request: 'lastBlock'});
498
498
 
499
499
  const node = await peernet.prepareMessage(data);
500
500
  promises.push(peer.request(node.encoded));
@@ -608,6 +608,7 @@ class Chain {
608
608
  this.#blocks.length;
609
609
  (this.#blocks.length) - blocksSynced;
610
610
  await this.#loadBlocks(this.#blocks);
611
+ this.#lastBlock = this.#blocks[this.#blocks.length - 1];
611
612
  const message = await new BlockMessage(this.lastBlock);
612
613
  await blockStore.put(await message.hash, message.encoded);
613
614
  await chainStore.put('lastBlock', this.lastBlock.hash);
@@ -1 +1 @@
1
- class ArtOnline extends class Token extends class Roles{#roles={OWNER:[],MINT:[],BURN:[]};constructor(roles){if(roles){if(!(roles instanceof Object))throw new Error("expected roles to be an object");this.#roles={...roles,...this.#roles}}else this.#grantRole(msg.sender,"OWNER")}get state(){return{roles:this.roles}}get roles(){return{...this.#roles}}hasRole(address,role){return!!this.#roles[role]&&-1!==this.#roles[role].indexOf(address)}#grantRole(address,role){if(this.hasRole(address,role))throw new Error(`${role} role already granted for ${address}`);this.#roles[role].push(address)}#revokeRole(address,role){if(!this.hasRole(address,role))throw new Error(`${role} role already revoked for ${address}`);if("OWNER"===role&&1===this.#roles[role].length)throw new Error("atleast one owner is needed!");this.#roles[role].splice(this.#roles[role].indexOf(address))}grantRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#grantRole(address,role)}revokeRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#revokeRole(address,role)}}{#name;#symbol;#holders=0;#balances={};#approvals={};#decimals=18;#totalSupply=BigNumber.from(0);constructor(name,symbol,decimals=18,state){if(!name)throw new Error("name undefined");if(!symbol)throw new Error("symbol undefined");super(state?.roles),this.#name=name,this.#symbol=symbol,this.#decimals=decimals}get state(){return{...super.state,holders:this.holders,balances:this.balances,approvals:{...this.#approvals},totalSupply:this.totalSupply}}get totalSupply(){return this.#totalSupply}get name(){return this.#name}get symbol(){return this.#symbol}get holders(){return this.#holders}get balances(){return{...this.#balances}}mint(to,amount){if(!this.hasRole(msg.sender,"MINT"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply.add(amount),this.#increaseBalance(to,amount)}burn(to,amount){if(!this.hasRole(msg.sender,"BURN"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply.sub(amount),this.#decreaseBalance(to,amount)}#beforeTransfer(from,to,amount){if(!this.#balances[from]||this.#balances[from]<amount)throw new Error("amount exceeds balance")}#updateHolders(address,previousBalance){"0x00"===this.#balances[address].toHexString()?this.#holders-=1:"0x00"!==this.#balances[address].toHexString()&&"0x00"===previousBalance.toHexString()&&(this.#holders+=1)}#increaseBalance(address,amount){this.#balances[address]||(this.#balances[address]=BigNumber.from(0));const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address].add(amount),this.#updateHolders(address,previousBalance)}#decreaseBalance(address,amount){const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address].sub(amount),this.#updateHolders(address,previousBalance)}balanceOf(address){return this.#balances[address]}setApproval(operator,amount){const owner=globalThis.msg.sender;this.#approvals[owner]||(this.#approvals[owner]={}),this.#approvals[owner][operator]=amount}approved(owner,operator,amount){return this.#approvals[owner][operator]===amount}transfer(from,to,amount){amount=BigNumber.from(amount),this.#beforeTransfer(from,to,amount),this.#decreaseBalance(from,amount),this.#increaseBalance(to,amount)}}{constructor(state){super("ArtOnline","ART",18,state)}}export{ArtOnline as default};
1
+ class Roles{#roles={OWNER:[],MINT:[],BURN:[]};constructor(roles){if(roles){if(!(roles instanceof Object))throw new Error("expected roles to be an object");this.#roles={...roles,...this.#roles}}else this.#grantRole(msg.sender,"OWNER")}get state(){return{roles:this.roles}}get roles(){return{...this.#roles}}hasRole(address,role){return!!this.#roles[role]&&-1!==this.#roles[role].indexOf(address)}#grantRole(address,role){if(this.hasRole(address,role))throw new Error(`${role} role already granted for ${address}`);this.#roles[role].push(address)}#revokeRole(address,role){if(!this.hasRole(address,role))throw new Error(`${role} role already revoked for ${address}`);if("OWNER"===role&&1===this.#roles[role].length)throw new Error("atleast one owner is needed!");this.#roles[role].splice(this.#roles[role].indexOf(address))}grantRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#grantRole(address,role)}revokeRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#revokeRole(address,role)}}class Token extends Roles{#name;#symbol;#holders=0;#balances={};#approvals={};#decimals=18;#totalSupply=BigNumber.from(0);constructor(name,symbol,decimals=18,state){if(!name)throw new Error("name undefined");if(!symbol)throw new Error("symbol undefined");super(state?.roles),this.#name=name,this.#symbol=symbol,this.#decimals=decimals}get state(){return{...super.state,holders:this.holders,balances:this.balances,approvals:{...this.#approvals},totalSupply:this.totalSupply}}get totalSupply(){return this.#totalSupply}get name(){return this.#name}get symbol(){return this.#symbol}get holders(){return this.#holders}get balances(){return{...this.#balances}}mint(to,amount){if(!this.hasRole(msg.sender,"MINT"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply.add(amount),this.#increaseBalance(to,amount)}burn(to,amount){if(!this.hasRole(msg.sender,"BURN"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply.sub(amount),this.#decreaseBalance(to,amount)}#beforeTransfer(from,to,amount){if(!this.#balances[from]||this.#balances[from]<amount)throw new Error("amount exceeds balance")}#updateHolders(address,previousBalance){"0x00"===this.#balances[address].toHexString()?this.#holders-=1:"0x00"!==this.#balances[address].toHexString()&&"0x00"===previousBalance.toHexString()&&(this.#holders+=1)}#increaseBalance(address,amount){this.#balances[address]||(this.#balances[address]=BigNumber.from(0));const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address].add(amount),this.#updateHolders(address,previousBalance)}#decreaseBalance(address,amount){const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address].sub(amount),this.#updateHolders(address,previousBalance)}balanceOf(address){return this.#balances[address]}setApproval(operator,amount){const owner=globalThis.msg.sender;this.#approvals[owner]||(this.#approvals[owner]={}),this.#approvals[owner][operator]=amount}approved(owner,operator,amount){return this.#approvals[owner][operator]===amount}transfer(from,to,amount){amount=BigNumber.from(amount),this.#beforeTransfer(from,to,amount),this.#decreaseBalance(from,amount),this.#increaseBalance(to,amount)}}class ArtOnline extends Token{constructor(state){super("ArtOnline","ART",18,state)}}export{ArtOnline as default};
@@ -486,7 +486,7 @@ class Chain {
486
486
  let promises = [];
487
487
  for (const peer of peernet.connections) {
488
488
  if (peer.peerId !== this.id) {
489
- let data = new peernet.protos['peernet-request']({request: 'lastBlock'});
489
+ let data = await new peernet.protos['peernet-request']({request: 'lastBlock'});
490
490
 
491
491
  const node = await peernet.prepareMessage(data);
492
492
  promises.push(peer.request(node.encoded));
@@ -600,6 +600,7 @@ class Chain {
600
600
  this.#blocks.length;
601
601
  (this.#blocks.length) - blocksSynced;
602
602
  await this.#loadBlocks(this.#blocks);
603
+ this.#lastBlock = this.#blocks[this.#blocks.length - 1];
603
604
  const message = await new BlockMessage(this.lastBlock);
604
605
  await blockStore.put(await message.hash, message.encoded);
605
606
  await chainStore.put('lastBlock', this.lastBlock.hash);
@@ -1 +1 @@
1
- class Token extends class Roles{#roles={OWNER:[],MINT:[],BURN:[]};constructor(roles){if(roles){if(!(roles instanceof Object))throw new Error("expected roles to be an object");this.#roles={...roles,...this.#roles}}else this.#grantRole(msg.sender,"OWNER")}get state(){return{roles:this.roles}}get roles(){return{...this.#roles}}hasRole(address,role){return!!this.#roles[role]&&-1!==this.#roles[role].indexOf(address)}#grantRole(address,role){if(this.hasRole(address,role))throw new Error(`${role} role already granted for ${address}`);this.#roles[role].push(address)}#revokeRole(address,role){if(!this.hasRole(address,role))throw new Error(`${role} role already revoked for ${address}`);if("OWNER"===role&&1===this.#roles[role].length)throw new Error("atleast one owner is needed!");this.#roles[role].splice(this.#roles[role].indexOf(address))}grantRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#grantRole(address,role)}revokeRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#revokeRole(address,role)}}{#name;#symbol;#holders=0;#balances={};#approvals={};#decimals=18;#totalSupply=BigNumber.from(0);constructor(name,symbol,decimals=18,state){if(!name)throw new Error("name undefined");if(!symbol)throw new Error("symbol undefined");super(state?.roles),this.#name=name,this.#symbol=symbol,this.#decimals=decimals}get state(){return{...super.state,holders:this.holders,balances:this.balances,approvals:{...this.#approvals},totalSupply:this.totalSupply}}get totalSupply(){return this.#totalSupply}get name(){return this.#name}get symbol(){return this.#symbol}get holders(){return this.#holders}get balances(){return{...this.#balances}}mint(to,amount){if(!this.hasRole(msg.sender,"MINT"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply.add(amount),this.#increaseBalance(to,amount)}burn(to,amount){if(!this.hasRole(msg.sender,"BURN"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply.sub(amount),this.#decreaseBalance(to,amount)}#beforeTransfer(from,to,amount){if(!this.#balances[from]||this.#balances[from]<amount)throw new Error("amount exceeds balance")}#updateHolders(address,previousBalance){"0x00"===this.#balances[address].toHexString()?this.#holders-=1:"0x00"!==this.#balances[address].toHexString()&&"0x00"===previousBalance.toHexString()&&(this.#holders+=1)}#increaseBalance(address,amount){this.#balances[address]||(this.#balances[address]=BigNumber.from(0));const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address].add(amount),this.#updateHolders(address,previousBalance)}#decreaseBalance(address,amount){const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address].sub(amount),this.#updateHolders(address,previousBalance)}balanceOf(address){return this.#balances[address]}setApproval(operator,amount){const owner=globalThis.msg.sender;this.#approvals[owner]||(this.#approvals[owner]={}),this.#approvals[owner][operator]=amount}approved(owner,operator,amount){return this.#approvals[owner][operator]===amount}transfer(from,to,amount){amount=BigNumber.from(amount),this.#beforeTransfer(from,to,amount),this.#decreaseBalance(from,amount),this.#increaseBalance(to,amount)}}export{Token as default};
1
+ class Roles{#roles={OWNER:[],MINT:[],BURN:[]};constructor(roles){if(roles){if(!(roles instanceof Object))throw new Error("expected roles to be an object");this.#roles={...roles,...this.#roles}}else this.#grantRole(msg.sender,"OWNER")}get state(){return{roles:this.roles}}get roles(){return{...this.#roles}}hasRole(address,role){return!!this.#roles[role]&&-1!==this.#roles[role].indexOf(address)}#grantRole(address,role){if(this.hasRole(address,role))throw new Error(`${role} role already granted for ${address}`);this.#roles[role].push(address)}#revokeRole(address,role){if(!this.hasRole(address,role))throw new Error(`${role} role already revoked for ${address}`);if("OWNER"===role&&1===this.#roles[role].length)throw new Error("atleast one owner is needed!");this.#roles[role].splice(this.#roles[role].indexOf(address))}grantRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#grantRole(address,role)}revokeRole(address,role){if(!this.hasRole(address,"OWNER"))throw new Error("Not allowed");this.#revokeRole(address,role)}}class Token extends Roles{#name;#symbol;#holders=0;#balances={};#approvals={};#decimals=18;#totalSupply=BigNumber.from(0);constructor(name,symbol,decimals=18,state){if(!name)throw new Error("name undefined");if(!symbol)throw new Error("symbol undefined");super(state?.roles),this.#name=name,this.#symbol=symbol,this.#decimals=decimals}get state(){return{...super.state,holders:this.holders,balances:this.balances,approvals:{...this.#approvals},totalSupply:this.totalSupply}}get totalSupply(){return this.#totalSupply}get name(){return this.#name}get symbol(){return this.#symbol}get holders(){return this.#holders}get balances(){return{...this.#balances}}mint(to,amount){if(!this.hasRole(msg.sender,"MINT"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply.add(amount),this.#increaseBalance(to,amount)}burn(to,amount){if(!this.hasRole(msg.sender,"BURN"))throw new Error("not allowed");this.#totalSupply=this.#totalSupply.sub(amount),this.#decreaseBalance(to,amount)}#beforeTransfer(from,to,amount){if(!this.#balances[from]||this.#balances[from]<amount)throw new Error("amount exceeds balance")}#updateHolders(address,previousBalance){"0x00"===this.#balances[address].toHexString()?this.#holders-=1:"0x00"!==this.#balances[address].toHexString()&&"0x00"===previousBalance.toHexString()&&(this.#holders+=1)}#increaseBalance(address,amount){this.#balances[address]||(this.#balances[address]=BigNumber.from(0));const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address].add(amount),this.#updateHolders(address,previousBalance)}#decreaseBalance(address,amount){const previousBalance=this.#balances[address];this.#balances[address]=this.#balances[address].sub(amount),this.#updateHolders(address,previousBalance)}balanceOf(address){return this.#balances[address]}setApproval(operator,amount){const owner=globalThis.msg.sender;this.#approvals[owner]||(this.#approvals[owner]={}),this.#approvals[owner][operator]=amount}approved(owner,operator,amount){return this.#approvals[owner][operator]===amount}transfer(from,to,amount){amount=BigNumber.from(amount),this.#beforeTransfer(from,to,amount),this.#decreaseBalance(from,amount),this.#increaseBalance(to,amount)}}export{Token as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/chain",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "<a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\"><img alt=\"Creative Commons Licence\" style=\"border-width:0\" src=\"https://i.creativecommons.org/l/by-nc/4.0/88x31.png\" /></a><br />This work is licensed under a <a rel=\"license\" href=\"http://creativecommons.org/licenses/by-nc/4.0/\">Creative Commons Attribution-NonCommercial 4.0 International License</a>.",
5
5
  "main": "./dist/node.js",
6
6
  "module": "./dist/chain.esm",
@@ -9,7 +9,7 @@
9
9
  "w": "rollup -c -w",
10
10
  "build": "npm run c && webpack && cp ./dist/*browser.js ./demo && cp ./dist/machine-worker.js ./demo/workers/machine-worker.js",
11
11
  "demo": "jsproject --serve ./demo --port 5478 --open demo",
12
- "test": "echo \"Error: no test specified\" && exit 1"
12
+ "test": "node test --openssl-legacy-provider"
13
13
  },
14
14
  "browserslist": "> 0.5%, last 2 versions, not dead",
15
15
  "keywords": [],
@@ -19,6 +19,7 @@
19
19
  "@rollup/plugin-json": "^4.1.0",
20
20
  "@rollup/plugin-strip": "^2.1.0",
21
21
  "@vandeurenglenn/debug": "^1.0.0",
22
+ "path-browserify": "^1.0.1",
22
23
  "rollup": "^2.70.1",
23
24
  "rollup-plugin-cleanup": "^3.2.1",
24
25
  "rollup-plugin-terser": "^7.0.2",
package/src/chain.js CHANGED
@@ -102,7 +102,7 @@ export default class Chain {
102
102
  let promises = []
103
103
  for (const peer of peernet.connections) {
104
104
  if (peer.peerId !== this.id) {
105
- let data = new peernet.protos['peernet-request']({request: 'lastBlock'})
105
+ let data = await new peernet.protos['peernet-request']({request: 'lastBlock'})
106
106
 
107
107
  const node = await peernet.prepareMessage(data)
108
108
  promises.push(peer.request(node.encoded))
@@ -216,6 +216,7 @@ export default class Chain {
216
216
  const end = this.#blocks.length
217
217
  const start = (this.#blocks.length) - blocksSynced
218
218
  await this.#loadBlocks(this.#blocks)
219
+ this.#lastBlock = this.#blocks[this.#blocks.length - 1]
219
220
  const message = await new BlockMessage(this.lastBlock)
220
221
  await blockStore.put(await message.hash, message.encoded)
221
222
  await chainStore.put('lastBlock', this.lastBlock.hash)
package/test/chain.js CHANGED
@@ -30,21 +30,21 @@
30
30
  const job = async () => {
31
31
  // setTimeout(async () => {
32
32
  let tx
33
- try {
34
- tx = await chain.createTransaction(chain.nativeToken, 'grantRole', [peernet.id, 'MINT'])
35
- await tx.wait()
33
+ // try {
34
+ // tx = await chain.createTransaction(chain.nativeToken, 'grantRole', [peernet.id, 'MINT'])
35
+ // await tx.wait()
36
36
 
37
- } catch (e) {
38
- console.log({e});
39
- }
37
+ // } catch (e) {
38
+ // console.log({e});
39
+ // }
40
40
 
41
- try {
42
- tx = await chain.createTransaction(chain.nativeToken, 'mint', [peernet.id, chain.utils.parseUnits('100000000000000').toString()])
41
+ // try {
42
+ // tx = await chain.createTransaction(chain.nativeToken, 'mint', [peernet.id, chain.utils.parseUnits('100000000000000').toString()])
43
43
 
44
- await tx.wait()
45
- } catch (e) {
46
- console.log({e});
47
- }
44
+ // await tx.wait()
45
+ // } catch (e) {
46
+ // console.log({e});
47
+ // }
48
48
  // return
49
49
  let nonce = await chain.getNonce(peernet.id)
50
50
  console.log({nonce});
package/webpack.config.js CHANGED
@@ -30,8 +30,8 @@ module.exports = [{
30
30
  // extensions: [ '.ts', '.js' ],
31
31
  fallback: {
32
32
  'vm': require.resolve("vm-browserify"),
33
- // "stream": require.resolve("stream-browserify"),
34
- // "buffer": require.resolve("buffer"),
33
+ "path": require.resolve("path-browserify"),
34
+ "child_process": false,
35
35
  "fs": false,
36
36
  "util": false,
37
37
  // "assert": require.resolve("assert/"),