@leofcoin/chain 1.1.12 → 1.1.13
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/demo/chain.browser.js +13 -13
- package/demo/node.browser.js +4 -1
- package/dist/chain.browser.js +13 -13
- package/dist/chain.js +13 -13
- package/dist/module/chain.js +13 -13
- package/dist/node.browser.js +4 -1
- package/package.json +3 -1
- package/src/chain.js +12 -12
- package/src/machine.js +1 -1
- package/test/chain.js +17 -17
package/demo/chain.browser.js
CHANGED
|
@@ -58569,7 +58569,7 @@ class Machine {
|
|
|
58569
58569
|
return this.#init()
|
|
58570
58570
|
}
|
|
58571
58571
|
|
|
58572
|
-
#createMessage(sender = peernet.
|
|
58572
|
+
#createMessage(sender = peernet.selectedAccount) {
|
|
58573
58573
|
return {
|
|
58574
58574
|
sender,
|
|
58575
58575
|
call: this.execute,
|
|
@@ -58953,7 +58953,7 @@ class Chain {
|
|
|
58953
58953
|
console.log('epoch');
|
|
58954
58954
|
const validators = await this.staticCall(addresses.validators, 'validators');
|
|
58955
58955
|
console.log(validators);
|
|
58956
|
-
if (!validators[peernet.
|
|
58956
|
+
if (!validators[peernet.selectedAccount]?.active) return
|
|
58957
58957
|
|
|
58958
58958
|
const start = new Date().getTime();
|
|
58959
58959
|
try {
|
|
@@ -59291,7 +59291,7 @@ async resolveBlock(hash) {
|
|
|
59291
59291
|
|
|
59292
59292
|
|
|
59293
59293
|
|
|
59294
|
-
async participate() {
|
|
59294
|
+
async participate(address) {
|
|
59295
59295
|
// TODO: validate participant
|
|
59296
59296
|
// hold min amount of 50k ART for 7 days
|
|
59297
59297
|
// lock the 50k
|
|
@@ -59299,7 +59299,7 @@ async resolveBlock(hash) {
|
|
|
59299
59299
|
// peerReputation(peerId)
|
|
59300
59300
|
// {bandwith: {up, down}, uptime}
|
|
59301
59301
|
this.participating = true;
|
|
59302
|
-
if (!await this.staticCall(addresses.validators, 'has', [
|
|
59302
|
+
if (!await this.staticCall(addresses.validators, 'has', [address])) await this.createTransactionFrom(address, addresses.validators, 'addValidator', [address]);
|
|
59303
59303
|
if (await this.hasTransactionToHandle() && !this.#runningEpoch) await this.#runEpoch();
|
|
59304
59304
|
|
|
59305
59305
|
// const runEpoch = () => setTimeout(async () => {
|
|
@@ -59388,7 +59388,7 @@ async resolveBlock(hash) {
|
|
|
59388
59388
|
const node = await peernet.prepareMessage(validator, data.encoded);
|
|
59389
59389
|
try {
|
|
59390
59390
|
const bw = await peer.request(node.encoded);
|
|
59391
|
-
console.log(bw);
|
|
59391
|
+
console.log({bw});
|
|
59392
59392
|
block.validators.push({
|
|
59393
59393
|
address: validator,
|
|
59394
59394
|
bw: bw.up + bw.down
|
|
@@ -59397,9 +59397,9 @@ async resolveBlock(hash) {
|
|
|
59397
59397
|
|
|
59398
59398
|
}
|
|
59399
59399
|
|
|
59400
|
-
} else if (peernet.
|
|
59400
|
+
} else if (peernet.selectedAccount === validator) {
|
|
59401
59401
|
block.validators.push({
|
|
59402
|
-
address: peernet.
|
|
59402
|
+
address: peernet.selectedAccount,
|
|
59403
59403
|
bw: peernet.bw.up + peernet.bw.down
|
|
59404
59404
|
});
|
|
59405
59405
|
|
|
@@ -59525,7 +59525,7 @@ async resolveBlock(hash) {
|
|
|
59525
59525
|
* @param {Number} nonce - total transaction count [optional]
|
|
59526
59526
|
*/
|
|
59527
59527
|
async createTransaction(to, method, params, nonce, signature) {
|
|
59528
|
-
return this.createTransactionFrom(peernet.
|
|
59528
|
+
return this.createTransactionFrom(peernet.selectedAccount, to, method, params, nonce)
|
|
59529
59529
|
}
|
|
59530
59530
|
|
|
59531
59531
|
|
|
@@ -59577,7 +59577,7 @@ async #signTransaction (transaction, wallet) {
|
|
|
59577
59577
|
* @returns {Object} transaction
|
|
59578
59578
|
*/
|
|
59579
59579
|
async createRawTransaction(transaction) {
|
|
59580
|
-
if (!transaction.from) transaction.from = peernet.
|
|
59580
|
+
if (!transaction.from) transaction.from = peernet.selectedAccount;
|
|
59581
59581
|
transaction.timestamp = Date.now();
|
|
59582
59582
|
|
|
59583
59583
|
if (transaction.nonce === undefined) {
|
|
@@ -59653,21 +59653,21 @@ async #signTransaction (transaction, wallet) {
|
|
|
59653
59653
|
* @param {String} contract - a contract string (see plugins/deployContract)
|
|
59654
59654
|
*/
|
|
59655
59655
|
async deployContract(contract, params = []) {
|
|
59656
|
-
globalThis.msg = {sender: peernet.
|
|
59656
|
+
globalThis.msg = {sender: peernet.selectedAccount, call: this.call};
|
|
59657
59657
|
|
|
59658
59658
|
const hash = await this.createContractAddress(creator, contract, params);
|
|
59659
59659
|
console.log(hash);
|
|
59660
59660
|
try {
|
|
59661
|
-
const tx = await this.createTransactionFrom(peernet.
|
|
59661
|
+
const tx = await this.createTransactionFrom(peernet.selectedAccount, addresses.contractFactory, 'deployContract', [hash, creator, contract, constructorParameters]);
|
|
59662
59662
|
} catch (e) {
|
|
59663
59663
|
throw e
|
|
59664
59664
|
}
|
|
59665
59665
|
return this.#machine.addContract(message)
|
|
59666
59666
|
}
|
|
59667
59667
|
|
|
59668
|
-
#createMessage(sender = peernet.
|
|
59668
|
+
#createMessage(sender = peernet.selectedAccount) {
|
|
59669
59669
|
return {
|
|
59670
|
-
sender
|
|
59670
|
+
sender,
|
|
59671
59671
|
call: this.call,
|
|
59672
59672
|
staticCall: this.staticCall,
|
|
59673
59673
|
delegate: this.delegate,
|
package/demo/node.browser.js
CHANGED
|
@@ -9132,7 +9132,8 @@ class Peernet {
|
|
|
9132
9132
|
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
|
|
9133
9133
|
let accounts = await walletStore.get('accounts');
|
|
9134
9134
|
accounts = new TextDecoder().decode(accounts);
|
|
9135
|
-
|
|
9135
|
+
const selected = await walletStore.get('selected-account');
|
|
9136
|
+
globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
|
|
9136
9137
|
|
|
9137
9138
|
// fixing account issue (string while needs to be a JSON)
|
|
9138
9139
|
// TODO: remove when on mainnet
|
|
@@ -9150,8 +9151,10 @@ class Peernet {
|
|
|
9150
9151
|
|
|
9151
9152
|
await walletStore.put('version', String(1));
|
|
9152
9153
|
await walletStore.put('accounts', JSON.stringify(accounts));
|
|
9154
|
+
await walletStore.put('selected-account', accounts[0][1]);
|
|
9153
9155
|
await walletStore.put('identity', JSON.stringify(identity));
|
|
9154
9156
|
|
|
9157
|
+
globalThis.peernet.selectedAccount = accounts[0][1];
|
|
9155
9158
|
this.id = identity.walletId;
|
|
9156
9159
|
}
|
|
9157
9160
|
this._peerHandler = new PeerDiscovery(this.id);
|
package/dist/chain.browser.js
CHANGED
|
@@ -58569,7 +58569,7 @@ class Machine {
|
|
|
58569
58569
|
return this.#init()
|
|
58570
58570
|
}
|
|
58571
58571
|
|
|
58572
|
-
#createMessage(sender = peernet.
|
|
58572
|
+
#createMessage(sender = peernet.selectedAccount) {
|
|
58573
58573
|
return {
|
|
58574
58574
|
sender,
|
|
58575
58575
|
call: this.execute,
|
|
@@ -58953,7 +58953,7 @@ class Chain {
|
|
|
58953
58953
|
console.log('epoch');
|
|
58954
58954
|
const validators = await this.staticCall(addresses.validators, 'validators');
|
|
58955
58955
|
console.log(validators);
|
|
58956
|
-
if (!validators[peernet.
|
|
58956
|
+
if (!validators[peernet.selectedAccount]?.active) return
|
|
58957
58957
|
|
|
58958
58958
|
const start = new Date().getTime();
|
|
58959
58959
|
try {
|
|
@@ -59291,7 +59291,7 @@ async resolveBlock(hash) {
|
|
|
59291
59291
|
|
|
59292
59292
|
|
|
59293
59293
|
|
|
59294
|
-
async participate() {
|
|
59294
|
+
async participate(address) {
|
|
59295
59295
|
// TODO: validate participant
|
|
59296
59296
|
// hold min amount of 50k ART for 7 days
|
|
59297
59297
|
// lock the 50k
|
|
@@ -59299,7 +59299,7 @@ async resolveBlock(hash) {
|
|
|
59299
59299
|
// peerReputation(peerId)
|
|
59300
59300
|
// {bandwith: {up, down}, uptime}
|
|
59301
59301
|
this.participating = true;
|
|
59302
|
-
if (!await this.staticCall(addresses.validators, 'has', [
|
|
59302
|
+
if (!await this.staticCall(addresses.validators, 'has', [address])) await this.createTransactionFrom(address, addresses.validators, 'addValidator', [address]);
|
|
59303
59303
|
if (await this.hasTransactionToHandle() && !this.#runningEpoch) await this.#runEpoch();
|
|
59304
59304
|
|
|
59305
59305
|
// const runEpoch = () => setTimeout(async () => {
|
|
@@ -59388,7 +59388,7 @@ async resolveBlock(hash) {
|
|
|
59388
59388
|
const node = await peernet.prepareMessage(validator, data.encoded);
|
|
59389
59389
|
try {
|
|
59390
59390
|
const bw = await peer.request(node.encoded);
|
|
59391
|
-
console.log(bw);
|
|
59391
|
+
console.log({bw});
|
|
59392
59392
|
block.validators.push({
|
|
59393
59393
|
address: validator,
|
|
59394
59394
|
bw: bw.up + bw.down
|
|
@@ -59397,9 +59397,9 @@ async resolveBlock(hash) {
|
|
|
59397
59397
|
|
|
59398
59398
|
}
|
|
59399
59399
|
|
|
59400
|
-
} else if (peernet.
|
|
59400
|
+
} else if (peernet.selectedAccount === validator) {
|
|
59401
59401
|
block.validators.push({
|
|
59402
|
-
address: peernet.
|
|
59402
|
+
address: peernet.selectedAccount,
|
|
59403
59403
|
bw: peernet.bw.up + peernet.bw.down
|
|
59404
59404
|
});
|
|
59405
59405
|
|
|
@@ -59525,7 +59525,7 @@ async resolveBlock(hash) {
|
|
|
59525
59525
|
* @param {Number} nonce - total transaction count [optional]
|
|
59526
59526
|
*/
|
|
59527
59527
|
async createTransaction(to, method, params, nonce, signature) {
|
|
59528
|
-
return this.createTransactionFrom(peernet.
|
|
59528
|
+
return this.createTransactionFrom(peernet.selectedAccount, to, method, params, nonce)
|
|
59529
59529
|
}
|
|
59530
59530
|
|
|
59531
59531
|
|
|
@@ -59577,7 +59577,7 @@ async #signTransaction (transaction, wallet) {
|
|
|
59577
59577
|
* @returns {Object} transaction
|
|
59578
59578
|
*/
|
|
59579
59579
|
async createRawTransaction(transaction) {
|
|
59580
|
-
if (!transaction.from) transaction.from = peernet.
|
|
59580
|
+
if (!transaction.from) transaction.from = peernet.selectedAccount;
|
|
59581
59581
|
transaction.timestamp = Date.now();
|
|
59582
59582
|
|
|
59583
59583
|
if (transaction.nonce === undefined) {
|
|
@@ -59653,21 +59653,21 @@ async #signTransaction (transaction, wallet) {
|
|
|
59653
59653
|
* @param {String} contract - a contract string (see plugins/deployContract)
|
|
59654
59654
|
*/
|
|
59655
59655
|
async deployContract(contract, params = []) {
|
|
59656
|
-
globalThis.msg = {sender: peernet.
|
|
59656
|
+
globalThis.msg = {sender: peernet.selectedAccount, call: this.call};
|
|
59657
59657
|
|
|
59658
59658
|
const hash = await this.createContractAddress(creator, contract, params);
|
|
59659
59659
|
console.log(hash);
|
|
59660
59660
|
try {
|
|
59661
|
-
const tx = await this.createTransactionFrom(peernet.
|
|
59661
|
+
const tx = await this.createTransactionFrom(peernet.selectedAccount, addresses.contractFactory, 'deployContract', [hash, creator, contract, constructorParameters]);
|
|
59662
59662
|
} catch (e) {
|
|
59663
59663
|
throw e
|
|
59664
59664
|
}
|
|
59665
59665
|
return this.#machine.addContract(message)
|
|
59666
59666
|
}
|
|
59667
59667
|
|
|
59668
|
-
#createMessage(sender = peernet.
|
|
59668
|
+
#createMessage(sender = peernet.selectedAccount) {
|
|
59669
59669
|
return {
|
|
59670
|
-
sender
|
|
59670
|
+
sender,
|
|
59671
59671
|
call: this.call,
|
|
59672
59672
|
staticCall: this.staticCall,
|
|
59673
59673
|
delegate: this.delegate,
|
package/dist/chain.js
CHANGED
|
@@ -68,7 +68,7 @@ class Machine {
|
|
|
68
68
|
return this.#init()
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
#createMessage(sender = peernet.
|
|
71
|
+
#createMessage(sender = peernet.selectedAccount) {
|
|
72
72
|
return {
|
|
73
73
|
sender,
|
|
74
74
|
call: this.execute,
|
|
@@ -452,7 +452,7 @@ class Chain {
|
|
|
452
452
|
console.log('epoch');
|
|
453
453
|
const validators = await this.staticCall(addresses.validators, 'validators');
|
|
454
454
|
console.log(validators);
|
|
455
|
-
if (!validators[peernet.
|
|
455
|
+
if (!validators[peernet.selectedAccount]?.active) return
|
|
456
456
|
|
|
457
457
|
const start = new Date().getTime();
|
|
458
458
|
try {
|
|
@@ -790,7 +790,7 @@ async resolveBlock(hash) {
|
|
|
790
790
|
|
|
791
791
|
|
|
792
792
|
|
|
793
|
-
async participate() {
|
|
793
|
+
async participate(address) {
|
|
794
794
|
// TODO: validate participant
|
|
795
795
|
// hold min amount of 50k ART for 7 days
|
|
796
796
|
// lock the 50k
|
|
@@ -798,7 +798,7 @@ async resolveBlock(hash) {
|
|
|
798
798
|
// peerReputation(peerId)
|
|
799
799
|
// {bandwith: {up, down}, uptime}
|
|
800
800
|
this.participating = true;
|
|
801
|
-
if (!await this.staticCall(addresses.validators, 'has', [
|
|
801
|
+
if (!await this.staticCall(addresses.validators, 'has', [address])) await this.createTransactionFrom(address, addresses.validators, 'addValidator', [address]);
|
|
802
802
|
if (await this.hasTransactionToHandle() && !this.#runningEpoch) await this.#runEpoch();
|
|
803
803
|
|
|
804
804
|
// const runEpoch = () => setTimeout(async () => {
|
|
@@ -887,7 +887,7 @@ async resolveBlock(hash) {
|
|
|
887
887
|
const node = await peernet.prepareMessage(validator, data.encoded);
|
|
888
888
|
try {
|
|
889
889
|
const bw = await peer.request(node.encoded);
|
|
890
|
-
console.log(bw);
|
|
890
|
+
console.log({bw});
|
|
891
891
|
block.validators.push({
|
|
892
892
|
address: validator,
|
|
893
893
|
bw: bw.up + bw.down
|
|
@@ -896,9 +896,9 @@ async resolveBlock(hash) {
|
|
|
896
896
|
|
|
897
897
|
}
|
|
898
898
|
|
|
899
|
-
} else if (peernet.
|
|
899
|
+
} else if (peernet.selectedAccount === validator) {
|
|
900
900
|
block.validators.push({
|
|
901
|
-
address: peernet.
|
|
901
|
+
address: peernet.selectedAccount,
|
|
902
902
|
bw: peernet.bw.up + peernet.bw.down
|
|
903
903
|
});
|
|
904
904
|
|
|
@@ -1024,7 +1024,7 @@ async resolveBlock(hash) {
|
|
|
1024
1024
|
* @param {Number} nonce - total transaction count [optional]
|
|
1025
1025
|
*/
|
|
1026
1026
|
async createTransaction(to, method, params, nonce, signature) {
|
|
1027
|
-
return this.createTransactionFrom(peernet.
|
|
1027
|
+
return this.createTransactionFrom(peernet.selectedAccount, to, method, params, nonce)
|
|
1028
1028
|
}
|
|
1029
1029
|
|
|
1030
1030
|
|
|
@@ -1076,7 +1076,7 @@ async #signTransaction (transaction, wallet) {
|
|
|
1076
1076
|
* @returns {Object} transaction
|
|
1077
1077
|
*/
|
|
1078
1078
|
async createRawTransaction(transaction) {
|
|
1079
|
-
if (!transaction.from) transaction.from = peernet.
|
|
1079
|
+
if (!transaction.from) transaction.from = peernet.selectedAccount;
|
|
1080
1080
|
transaction.timestamp = Date.now();
|
|
1081
1081
|
|
|
1082
1082
|
if (transaction.nonce === undefined) {
|
|
@@ -1152,21 +1152,21 @@ async #signTransaction (transaction, wallet) {
|
|
|
1152
1152
|
* @param {String} contract - a contract string (see plugins/deployContract)
|
|
1153
1153
|
*/
|
|
1154
1154
|
async deployContract(contract, params = []) {
|
|
1155
|
-
globalThis.msg = {sender: peernet.
|
|
1155
|
+
globalThis.msg = {sender: peernet.selectedAccount, call: this.call};
|
|
1156
1156
|
|
|
1157
1157
|
const hash = await this.createContractAddress(creator, contract, params);
|
|
1158
1158
|
console.log(hash);
|
|
1159
1159
|
try {
|
|
1160
|
-
const tx = await this.createTransactionFrom(peernet.
|
|
1160
|
+
const tx = await this.createTransactionFrom(peernet.selectedAccount, addresses.contractFactory, 'deployContract', [hash, creator, contract, constructorParameters]);
|
|
1161
1161
|
} catch (e) {
|
|
1162
1162
|
throw e
|
|
1163
1163
|
}
|
|
1164
1164
|
return this.#machine.addContract(message)
|
|
1165
1165
|
}
|
|
1166
1166
|
|
|
1167
|
-
#createMessage(sender = peernet.
|
|
1167
|
+
#createMessage(sender = peernet.selectedAccount) {
|
|
1168
1168
|
return {
|
|
1169
|
-
sender
|
|
1169
|
+
sender,
|
|
1170
1170
|
call: this.call,
|
|
1171
1171
|
staticCall: this.staticCall,
|
|
1172
1172
|
delegate: this.delegate,
|
package/dist/module/chain.js
CHANGED
|
@@ -59,7 +59,7 @@ class Machine {
|
|
|
59
59
|
return this.#init()
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
#createMessage(sender = peernet.
|
|
62
|
+
#createMessage(sender = peernet.selectedAccount) {
|
|
63
63
|
return {
|
|
64
64
|
sender,
|
|
65
65
|
call: this.execute,
|
|
@@ -443,7 +443,7 @@ class Chain {
|
|
|
443
443
|
console.log('epoch');
|
|
444
444
|
const validators = await this.staticCall(addresses.validators, 'validators');
|
|
445
445
|
console.log(validators);
|
|
446
|
-
if (!validators[peernet.
|
|
446
|
+
if (!validators[peernet.selectedAccount]?.active) return
|
|
447
447
|
|
|
448
448
|
const start = new Date().getTime();
|
|
449
449
|
try {
|
|
@@ -781,7 +781,7 @@ async resolveBlock(hash) {
|
|
|
781
781
|
|
|
782
782
|
|
|
783
783
|
|
|
784
|
-
async participate() {
|
|
784
|
+
async participate(address) {
|
|
785
785
|
// TODO: validate participant
|
|
786
786
|
// hold min amount of 50k ART for 7 days
|
|
787
787
|
// lock the 50k
|
|
@@ -789,7 +789,7 @@ async resolveBlock(hash) {
|
|
|
789
789
|
// peerReputation(peerId)
|
|
790
790
|
// {bandwith: {up, down}, uptime}
|
|
791
791
|
this.participating = true;
|
|
792
|
-
if (!await this.staticCall(addresses.validators, 'has', [
|
|
792
|
+
if (!await this.staticCall(addresses.validators, 'has', [address])) await this.createTransactionFrom(address, addresses.validators, 'addValidator', [address]);
|
|
793
793
|
if (await this.hasTransactionToHandle() && !this.#runningEpoch) await this.#runEpoch();
|
|
794
794
|
|
|
795
795
|
// const runEpoch = () => setTimeout(async () => {
|
|
@@ -878,7 +878,7 @@ async resolveBlock(hash) {
|
|
|
878
878
|
const node = await peernet.prepareMessage(validator, data.encoded);
|
|
879
879
|
try {
|
|
880
880
|
const bw = await peer.request(node.encoded);
|
|
881
|
-
console.log(bw);
|
|
881
|
+
console.log({bw});
|
|
882
882
|
block.validators.push({
|
|
883
883
|
address: validator,
|
|
884
884
|
bw: bw.up + bw.down
|
|
@@ -887,9 +887,9 @@ async resolveBlock(hash) {
|
|
|
887
887
|
|
|
888
888
|
}
|
|
889
889
|
|
|
890
|
-
} else if (peernet.
|
|
890
|
+
} else if (peernet.selectedAccount === validator) {
|
|
891
891
|
block.validators.push({
|
|
892
|
-
address: peernet.
|
|
892
|
+
address: peernet.selectedAccount,
|
|
893
893
|
bw: peernet.bw.up + peernet.bw.down
|
|
894
894
|
});
|
|
895
895
|
|
|
@@ -1015,7 +1015,7 @@ async resolveBlock(hash) {
|
|
|
1015
1015
|
* @param {Number} nonce - total transaction count [optional]
|
|
1016
1016
|
*/
|
|
1017
1017
|
async createTransaction(to, method, params, nonce, signature) {
|
|
1018
|
-
return this.createTransactionFrom(peernet.
|
|
1018
|
+
return this.createTransactionFrom(peernet.selectedAccount, to, method, params, nonce)
|
|
1019
1019
|
}
|
|
1020
1020
|
|
|
1021
1021
|
|
|
@@ -1067,7 +1067,7 @@ async #signTransaction (transaction, wallet) {
|
|
|
1067
1067
|
* @returns {Object} transaction
|
|
1068
1068
|
*/
|
|
1069
1069
|
async createRawTransaction(transaction) {
|
|
1070
|
-
if (!transaction.from) transaction.from = peernet.
|
|
1070
|
+
if (!transaction.from) transaction.from = peernet.selectedAccount;
|
|
1071
1071
|
transaction.timestamp = Date.now();
|
|
1072
1072
|
|
|
1073
1073
|
if (transaction.nonce === undefined) {
|
|
@@ -1143,21 +1143,21 @@ async #signTransaction (transaction, wallet) {
|
|
|
1143
1143
|
* @param {String} contract - a contract string (see plugins/deployContract)
|
|
1144
1144
|
*/
|
|
1145
1145
|
async deployContract(contract, params = []) {
|
|
1146
|
-
globalThis.msg = {sender: peernet.
|
|
1146
|
+
globalThis.msg = {sender: peernet.selectedAccount, call: this.call};
|
|
1147
1147
|
|
|
1148
1148
|
const hash = await this.createContractAddress(creator, contract, params);
|
|
1149
1149
|
console.log(hash);
|
|
1150
1150
|
try {
|
|
1151
|
-
const tx = await this.createTransactionFrom(peernet.
|
|
1151
|
+
const tx = await this.createTransactionFrom(peernet.selectedAccount, addresses.contractFactory, 'deployContract', [hash, creator, contract, constructorParameters]);
|
|
1152
1152
|
} catch (e) {
|
|
1153
1153
|
throw e
|
|
1154
1154
|
}
|
|
1155
1155
|
return this.#machine.addContract(message)
|
|
1156
1156
|
}
|
|
1157
1157
|
|
|
1158
|
-
#createMessage(sender = peernet.
|
|
1158
|
+
#createMessage(sender = peernet.selectedAccount) {
|
|
1159
1159
|
return {
|
|
1160
|
-
sender
|
|
1160
|
+
sender,
|
|
1161
1161
|
call: this.call,
|
|
1162
1162
|
staticCall: this.staticCall,
|
|
1163
1163
|
delegate: this.delegate,
|
package/dist/node.browser.js
CHANGED
|
@@ -9132,7 +9132,8 @@ class Peernet {
|
|
|
9132
9132
|
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
|
|
9133
9133
|
let accounts = await walletStore.get('accounts');
|
|
9134
9134
|
accounts = new TextDecoder().decode(accounts);
|
|
9135
|
-
|
|
9135
|
+
const selected = await walletStore.get('selected-account');
|
|
9136
|
+
globalThis.peernet.selectedAccount = new TextDecoder().decode(selected);
|
|
9136
9137
|
|
|
9137
9138
|
// fixing account issue (string while needs to be a JSON)
|
|
9138
9139
|
// TODO: remove when on mainnet
|
|
@@ -9150,8 +9151,10 @@ class Peernet {
|
|
|
9150
9151
|
|
|
9151
9152
|
await walletStore.put('version', String(1));
|
|
9152
9153
|
await walletStore.put('accounts', JSON.stringify(accounts));
|
|
9154
|
+
await walletStore.put('selected-account', accounts[0][1]);
|
|
9153
9155
|
await walletStore.put('identity', JSON.stringify(identity));
|
|
9154
9156
|
|
|
9157
|
+
globalThis.peernet.selectedAccount = accounts[0][1];
|
|
9155
9158
|
this.id = identity.walletId;
|
|
9156
9159
|
}
|
|
9157
9160
|
this._peerHandler = new PeerDiscovery(this.id);
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/chain",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.13",
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"c": "rollup -c",
|
|
9
9
|
"w": "rollup -c -w",
|
|
10
|
+
"docs": "node_modules/.bin/jsdoc src/chain.js",
|
|
10
11
|
"build": "npm run c && webpack && cp ./dist/*browser.js ./demo && cp -r ./dist/browser/workers/ ./demo",
|
|
11
12
|
"demo": "jsproject --serve ./demo --port 5478 --open demo",
|
|
12
13
|
"test": "node test --openssl-legacy-provider",
|
|
@@ -21,6 +22,7 @@
|
|
|
21
22
|
"@rollup/plugin-strip": "^2.1.0",
|
|
22
23
|
"@vandeurenglenn/debug": "^1.0.0",
|
|
23
24
|
"crypto-browserify": "^3.12.0",
|
|
25
|
+
"jsdoc": "^4.0.0",
|
|
24
26
|
"os-browserify": "^0.3.0",
|
|
25
27
|
"path-browserify": "^1.0.1",
|
|
26
28
|
"rollup": "^2.70.1",
|
package/src/chain.js
CHANGED
|
@@ -55,7 +55,7 @@ export default class Chain {
|
|
|
55
55
|
console.log('epoch');
|
|
56
56
|
const validators = await this.staticCall(addresses.validators, 'validators')
|
|
57
57
|
console.log(validators);
|
|
58
|
-
if (!validators[peernet.
|
|
58
|
+
if (!validators[peernet.selectedAccount]?.active) return
|
|
59
59
|
|
|
60
60
|
const start = new Date().getTime()
|
|
61
61
|
try {
|
|
@@ -396,7 +396,7 @@ async resolveBlock(hash) {
|
|
|
396
396
|
|
|
397
397
|
|
|
398
398
|
|
|
399
|
-
async participate() {
|
|
399
|
+
async participate(address) {
|
|
400
400
|
// TODO: validate participant
|
|
401
401
|
// hold min amount of 50k ART for 7 days
|
|
402
402
|
// lock the 50k
|
|
@@ -404,7 +404,7 @@ async resolveBlock(hash) {
|
|
|
404
404
|
// peerReputation(peerId)
|
|
405
405
|
// {bandwith: {up, down}, uptime}
|
|
406
406
|
this.participating = true
|
|
407
|
-
if (!await this.staticCall(addresses.validators, 'has', [
|
|
407
|
+
if (!await this.staticCall(addresses.validators, 'has', [address])) await this.createTransactionFrom(address, addresses.validators, 'addValidator', [address])
|
|
408
408
|
if (await this.hasTransactionToHandle() && !this.#runningEpoch) await this.#runEpoch()
|
|
409
409
|
|
|
410
410
|
// const runEpoch = () => setTimeout(async () => {
|
|
@@ -493,7 +493,7 @@ async resolveBlock(hash) {
|
|
|
493
493
|
const node = await peernet.prepareMessage(validator, data.encoded)
|
|
494
494
|
try {
|
|
495
495
|
const bw = await peer.request(node.encoded)
|
|
496
|
-
console.log(bw);
|
|
496
|
+
console.log({bw});
|
|
497
497
|
block.validators.push({
|
|
498
498
|
address: validator,
|
|
499
499
|
bw: bw.up + bw.down
|
|
@@ -502,9 +502,9 @@ async resolveBlock(hash) {
|
|
|
502
502
|
|
|
503
503
|
}
|
|
504
504
|
|
|
505
|
-
} else if (peernet.
|
|
505
|
+
} else if (peernet.selectedAccount === validator) {
|
|
506
506
|
block.validators.push({
|
|
507
|
-
address: peernet.
|
|
507
|
+
address: peernet.selectedAccount,
|
|
508
508
|
bw: peernet.bw.up + peernet.bw.down
|
|
509
509
|
})
|
|
510
510
|
|
|
@@ -630,7 +630,7 @@ async resolveBlock(hash) {
|
|
|
630
630
|
* @param {Number} nonce - total transaction count [optional]
|
|
631
631
|
*/
|
|
632
632
|
async createTransaction(to, method, params, nonce, signature) {
|
|
633
|
-
return this.createTransactionFrom(peernet.
|
|
633
|
+
return this.createTransactionFrom(peernet.selectedAccount, to, method, params, nonce)
|
|
634
634
|
}
|
|
635
635
|
|
|
636
636
|
|
|
@@ -682,7 +682,7 @@ async #signTransaction (transaction, wallet) {
|
|
|
682
682
|
* @returns {Object} transaction
|
|
683
683
|
*/
|
|
684
684
|
async createRawTransaction(transaction) {
|
|
685
|
-
if (!transaction.from) transaction.from = peernet.
|
|
685
|
+
if (!transaction.from) transaction.from = peernet.selectedAccount
|
|
686
686
|
transaction.timestamp = Date.now()
|
|
687
687
|
|
|
688
688
|
if (transaction.nonce === undefined) {
|
|
@@ -758,21 +758,21 @@ async #signTransaction (transaction, wallet) {
|
|
|
758
758
|
* @param {String} contract - a contract string (see plugins/deployContract)
|
|
759
759
|
*/
|
|
760
760
|
async deployContract(contract, params = []) {
|
|
761
|
-
globalThis.msg = {sender: peernet.
|
|
761
|
+
globalThis.msg = {sender: peernet.selectedAccount, call: this.call}
|
|
762
762
|
|
|
763
763
|
const hash = await this.createContractAddress(creator, contract, params)
|
|
764
764
|
console.log(hash);
|
|
765
765
|
try {
|
|
766
|
-
const tx = await this.createTransactionFrom(peernet.
|
|
766
|
+
const tx = await this.createTransactionFrom(peernet.selectedAccount, addresses.contractFactory, 'deployContract', [hash, creator, contract, constructorParameters])
|
|
767
767
|
} catch (e) {
|
|
768
768
|
throw e
|
|
769
769
|
}
|
|
770
770
|
return this.#machine.addContract(message)
|
|
771
771
|
}
|
|
772
772
|
|
|
773
|
-
#createMessage(sender = peernet.
|
|
773
|
+
#createMessage(sender = peernet.selectedAccount) {
|
|
774
774
|
return {
|
|
775
|
-
sender
|
|
775
|
+
sender,
|
|
776
776
|
call: this.call,
|
|
777
777
|
staticCall: this.staticCall,
|
|
778
778
|
delegate: this.delegate,
|
package/src/machine.js
CHANGED
package/test/chain.js
CHANGED
|
@@ -30,23 +30,23 @@
|
|
|
30
30
|
const job = async () => {
|
|
31
31
|
// setTimeout(async () => {
|
|
32
32
|
let tx
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
try {
|
|
34
|
+
tx = await chain.createTransaction(chain.nativeToken, 'grantRole', [peernet.selectedAccount, 'MINT'])
|
|
35
|
+
await tx.wait()
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
} catch (e) {
|
|
38
|
+
console.log({e});
|
|
39
|
+
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
try {
|
|
42
|
+
tx = await chain.createTransaction(chain.nativeToken, 'mint', [peernet.selectedAccount, chain.utils.parseUnits('100000000000000').toString()])
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let nonce = await chain.getNonce(peernet.
|
|
44
|
+
await tx.wait()
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.log({e});
|
|
47
|
+
}
|
|
48
|
+
return
|
|
49
|
+
let nonce = await chain.getNonce(peernet.selectedAccount)
|
|
50
50
|
console.log({nonce});
|
|
51
51
|
// return
|
|
52
52
|
let promises = []
|
|
@@ -54,7 +54,7 @@ const job = async () => {
|
|
|
54
54
|
for (let i = 0; i < 10; i++) {
|
|
55
55
|
// contract , method, from, to, amount, (optional) nonce
|
|
56
56
|
nonce += 1
|
|
57
|
-
promises.push(chain.createTransaction(chain.nativeToken, 'transfer', [peernet.
|
|
57
|
+
promises.push(chain.createTransaction(chain.nativeToken, 'transfer', [peernet.selectedAccount, '6zqut21djrRNJAniaTByovGhnBGs5h9wfkP35mzjZkEBZwnQVo', chain.utils.parseUnits('100').toString()], nonce))
|
|
58
58
|
}
|
|
59
59
|
promises = await Promise.allSettled(promises)
|
|
60
60
|
promises = await Promise.allSettled(promises.map(({value}) => value.wait()))
|
|
@@ -76,7 +76,7 @@ const job = async () => {
|
|
|
76
76
|
// contract , method, from, to, amount, (optional) nonce
|
|
77
77
|
|
|
78
78
|
nonce += 1
|
|
79
|
-
promises.push(chain.createTransaction(chain.nativeToken, 'transfer', [peernet.
|
|
79
|
+
promises.push(chain.createTransaction(chain.nativeToken, 'transfer', [peernet.selectedAccount, '6zqut21djrRNJAniaTByovGhnBGs5h9wfkP35mzjZkEBZwnQVo', chain.utils.parseUnits('100').toString()], nonce))
|
|
80
80
|
}
|
|
81
81
|
promises = await Promise.allSettled(promises)
|
|
82
82
|
promises = await Promise.allSettled(promises.map(({value}) => value.wait()))
|
|
@@ -91,7 +91,7 @@ const job = async () => {
|
|
|
91
91
|
// contract , method, from, to, amount, (optional) nonce
|
|
92
92
|
|
|
93
93
|
nonce += 1
|
|
94
|
-
promises.push(chain.createTransaction(chain.nativeToken, 'transfer', [peernet.
|
|
94
|
+
promises.push(chain.createTransaction(chain.nativeToken, 'transfer', [peernet.selectedAccount, '6zqut21djrRNJAniaTByovGhnBGs5h9wfkP35mzjZkEBZwnQVo', chain.utils.parseUnits('100').toString()], nonce))
|
|
95
95
|
}
|
|
96
96
|
promises = await Promise.allSettled(promises)
|
|
97
97
|
promises = await Promise.allSettled(promises.map(({value}) => value.wait()))
|