@leofcoin/chain 1.3.9 → 1.3.10

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/src/chain.js CHANGED
@@ -58,7 +58,6 @@ export default class Chain {
58
58
  const validators = await this.staticCall(addresses.validators, 'validators')
59
59
  console.log(validators);
60
60
  if (!validators[peernet.selectedAccount]?.active) return
61
-
62
61
  const start = Date.now()
63
62
  try {
64
63
  await this.#createBlock()
@@ -647,7 +646,7 @@ async resolveBlock(hash) {
647
646
 
648
647
  /**
649
648
  *
650
- * @param {Object} transaction {}
649
+ * @param {Transaction} transaction
651
650
  * @param {String} transaction.from address
652
651
  * @param {String} transaction.to address
653
652
  * @param {Object} transaction.params {}
@@ -662,8 +661,8 @@ async createTransactionHash(transaction) {
662
661
  }
663
662
 
664
663
  /**
665
- * @params {object} transaction -
666
- * @params {object} wallet - any wallet/signer that supports sign(RAWtransaction)
664
+ * @param {Transaction} transaction
665
+ * @param {object} wallet any wallet/signer that supports sign(RAWtransaction)
667
666
  */
668
667
  async #signTransaction (transaction, wallet) {
669
668
  return wallet.sign(await this.createTransactionHash(transaction))
@@ -682,14 +681,14 @@ async #signTransaction (transaction, wallet) {
682
681
 
683
682
  /**
684
683
  *
685
- * @param {Object} transaction
684
+ * @param {Transaction} transaction
686
685
  * @param {Address} transaction.from
687
686
  * @param {Address} transaction.to
688
687
  * @param {String} transaction.method
689
688
  * @param {Array} transaction.params
690
689
  * @param {Number} transaction.nonce
691
690
  *
692
- * @returns {Object} transaction
691
+ * @returns {RawTransaction} transaction
693
692
  */
694
693
  async createRawTransaction(transaction) {
695
694
  if (!transaction.from) transaction.from = peernet.selectedAccount
@@ -710,13 +709,14 @@ async #signTransaction (transaction, wallet) {
710
709
  * data is undefined when nothing is returned
711
710
  * error is thrown on error so undefined data doesn't mean there is an error...
712
711
  *
713
- * @param {String} from - the sender address
714
- * @param {String} to - the contract address for the contract to interact with
712
+ * @param {Address} from - the sender address
713
+ * @param {Address} to - the contract address for the contract to interact with
715
714
  * @param {String} method - the method/function to run
716
715
  * @param {Array} params - array of paramters to apply to the contract method
717
716
  * @param {Number} nonce - total transaction count [optional]
718
717
  */
719
718
  async createTransactionFrom(from, to, method, parameters, nonce) {
719
+
720
720
  try {
721
721
 
722
722
  const rawTransaction = await this.createRawTransaction({from, to, nonce, method, params: parameters})
@@ -746,6 +746,7 @@ async #signTransaction (transaction, wallet) {
746
746
  await transactionPoolStore.put(await message.hash, message.encoded)
747
747
  peernet.publish('add-transaction', message.encoded)
748
748
  this.#addTransaction(message.encoded)
749
+ debug('creating tx')
749
750
  return {hash: await message.hash, data, fee: await calculateFee(message.decoded), wait}
750
751
  } catch (error) {
751
752
  console.log(error)
@@ -754,10 +755,24 @@ async #signTransaction (transaction, wallet) {
754
755
 
755
756
  }
756
757
 
758
+ /**
759
+ *
760
+ * @param {Address} creator
761
+ * @param {String} contract
762
+ * @param {Array} constructorParameters
763
+ * @returns lib.createContractMessage
764
+ */
757
765
  async createContractMessage(creator, contract, constructorParameters = []) {
758
766
  return createContractMessage(creator, contract, constructorParameters)
759
767
  }
760
768
 
769
+ /**
770
+ *
771
+ * @param {Address} creator
772
+ * @param {String} contract
773
+ * @param {Array} constructorParameters
774
+ * @returns {Address}
775
+ */
761
776
  async createContractAddress(creator, contract, constructorParameters = []) {
762
777
  contract = await this.createContractMessage(creator, contract, constructorParameters)
763
778
  return contract.hash
@@ -779,6 +794,11 @@ async #signTransaction (transaction, wallet) {
779
794
  return this.createTransactionFrom(peernet.selectedAccount, addresses.contractFactory, 'registerContract', [await message.hash])
780
795
  }
781
796
 
797
+ /**
798
+ *
799
+ * @param {Address} sender
800
+ * @returns {globalMessage}
801
+ */
782
802
  #createMessage(sender = peernet.selectedAccount) {
783
803
  return {
784
804
  sender,
@@ -789,12 +809,27 @@ async #signTransaction (transaction, wallet) {
789
809
  }
790
810
  }
791
811
 
812
+ /**
813
+ *
814
+ * @param {Address} sender
815
+ * @param {Address} contract
816
+ * @param {String} method
817
+ * @param {Array} parameters
818
+ * @returns
819
+ */
792
820
  internalCall(sender, contract, method, parameters) {
793
821
  globalThis.msg = this.#createMessage(sender)
794
822
 
795
823
  return this.#machine.execute(contract, method, parameters)
796
824
  }
797
825
 
826
+ /**
827
+ *
828
+ * @param {Address} contract
829
+ * @param {String} method
830
+ * @param {Array} parameters
831
+ * @returns
832
+ */
798
833
  call(contract, method, parameters) {
799
834
  globalThis.msg = this.#createMessage()
800
835
 
package/src/machine.js CHANGED
@@ -109,22 +109,27 @@ export default class Machine {
109
109
 
110
110
  }
111
111
 
112
+ /**
113
+ *
114
+ * @param {Address} contract
115
+ * @param {String} method
116
+ * @param {Array} parameters
117
+ * @returns Promise<message>
118
+ */
112
119
  async execute(contract, method, parameters) {
113
- /** */
114
120
  try {
115
121
  if (contract === contractFactory && method === 'registerContract') {
116
122
  if (this.#contracts[parameters[0]]) throw new Error(`duplicate contract @${parameters[0]}`)
117
123
  let message;
118
- if (!contractStore.has(parameters[0])) {
124
+ if (!await contractStore.has(parameters[0])) {
119
125
  message = await peernet.get(parameters[0], 'contract')
120
- message = new ContractMessage(message)
126
+ message = await new ContractMessage(message)
121
127
  await contractStore.put(await message.hash, message.encoded)
122
128
  }
123
129
  if (!message) {
124
130
  message = await contractStore.get(parameters[0])
125
- message = new ContractMessage(message)
131
+ message = await new ContractMessage(message)
126
132
  }
127
-
128
133
  if (!this.#contracts[await message.hash]) await this.#runContract(message)
129
134
  }
130
135
  } catch (error) {
@@ -0,0 +1,21 @@
1
+ type Address = string
2
+
3
+ interface Transaction {
4
+ to: Address,
5
+ from: Address,
6
+ method: String,
7
+ params: string[],
8
+ nonce: Number
9
+ }
10
+
11
+ interface RawTransaction extends Transaction {
12
+ timestamp: Number
13
+ }
14
+
15
+ interface globalMessage {
16
+ sender: Address,
17
+ call: Function,
18
+ staticCall: Function,
19
+ delegate: Function,
20
+ staticDelegate: Function
21
+ }
package/test/chain.js CHANGED
@@ -33,22 +33,22 @@ console.log(peernet.selectedAccount);
33
33
  const job = async () => {
34
34
  // setTimeout(async () => {
35
35
  let tx
36
- try {
37
- tx = await chain.createTransaction(chain.nativeToken, 'grantRole', [peernet.selectedAccount, 'MINT'])
38
- await tx.wait()
36
+ // try {
37
+ // tx = await chain.createTransaction(chain.nativeToken, 'grantRole', [peernet.selectedAccount, 'MINT'])
38
+ // await tx.wait()
39
39
 
40
- } catch (e) {
41
- console.log({e});
42
- }
40
+ // } catch (e) {
41
+ // console.log({e});
42
+ // }
43
43
 
44
- try {
45
- tx = await chain.createTransaction(chain.nativeToken, 'mint', [peernet.selectedAccount, chain.utils.parseUnits('100000000000000').toString()])
44
+ // try {
45
+ // tx = await chain.createTransaction(chain.nativeToken, 'mint', [peernet.selectedAccount, chain.utils.parseUnits('100000000000000').toString()])
46
46
 
47
- await tx.wait()
48
- } catch (e) {
49
- console.log({e});
50
- }
51
- return
47
+ // await tx.wait()
48
+ // } catch (e) {
49
+ // console.log({e});
50
+ // }
51
+ // return
52
52
  let nonce = await chain.getNonce(peernet.selectedAccount)
53
53
  console.log({nonce});
54
54
  // return
@@ -1,10 +0,0 @@
1
- (self["webpackChunk_leofcoin_chain"] = self["webpackChunk_leofcoin_chain"] || []).push([[865],{
2
-
3
- /***/ 865:
4
- /***/ (function() {
5
-
6
- /* (ignored) */
7
-
8
- /***/ })
9
-
10
- }])