@leofcoin/chain 1.4.4 → 1.4.5
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/package.json +1 -1
- package/src/chain.js +5 -5
- package/src/machine.js +2 -2
- package/src/transaction.js +12 -12
- package/test/chain.js +1 -1
package/package.json
CHANGED
package/src/chain.js
CHANGED
|
@@ -205,7 +205,7 @@ export default class Chain extends Contract {
|
|
|
205
205
|
for (const value of promises) {
|
|
206
206
|
if (value.index > latest.index) {
|
|
207
207
|
latest.index = value.index;
|
|
208
|
-
latest.hash = value.hash;
|
|
208
|
+
latest.hash = await value.hash();
|
|
209
209
|
}
|
|
210
210
|
}
|
|
211
211
|
|
|
@@ -391,7 +391,7 @@ async resolveBlock(hash) {
|
|
|
391
391
|
// console.log(block);
|
|
392
392
|
const blockMessage = await new BlockMessage(new Uint8Array(Object.values(block)))
|
|
393
393
|
await Promise.all(blockMessage.decoded.transactions
|
|
394
|
-
.map(async transaction => transactionPoolStore.delete(
|
|
394
|
+
.map(async transaction => transactionPoolStore.delete(transaction.hash)))
|
|
395
395
|
const hash = await blockMessage.hash()
|
|
396
396
|
|
|
397
397
|
await blockStore.put(hash, blockMessage.encoded)
|
|
@@ -557,7 +557,7 @@ async resolveBlock(hash) {
|
|
|
557
557
|
|
|
558
558
|
try {
|
|
559
559
|
await Promise.all(block.transactions
|
|
560
|
-
.map(async transaction => transactionPoolStore.delete(
|
|
560
|
+
.map(async transaction => transactionPoolStore.delete(transaction.hash)))
|
|
561
561
|
|
|
562
562
|
|
|
563
563
|
let blockMessage = await new BlockMessage(block)
|
|
@@ -581,9 +581,9 @@ async resolveBlock(hash) {
|
|
|
581
581
|
|
|
582
582
|
|
|
583
583
|
async #addTransaction(transaction) {
|
|
584
|
-
try {
|
|
585
|
-
const hash = await transaction.hash()
|
|
584
|
+
try {
|
|
586
585
|
transaction = await new TransactionMessage(transaction)
|
|
586
|
+
const hash = await transaction.hash()
|
|
587
587
|
const has = await transactionPoolStore.has(hash)
|
|
588
588
|
if (!has) await transactionPoolStore.put(hash, transaction.encoded)
|
|
589
589
|
if (this.#participating && !this.#runningEpoch) this.#runEpoch()
|
package/src/machine.js
CHANGED
|
@@ -50,7 +50,7 @@ export default class Machine {
|
|
|
50
50
|
break
|
|
51
51
|
}
|
|
52
52
|
case 'response': {
|
|
53
|
-
pubsub.publish(data.id, data.value)
|
|
53
|
+
pubsub.publish(data.id, data.value || true)
|
|
54
54
|
break
|
|
55
55
|
}
|
|
56
56
|
}
|
|
@@ -140,7 +140,7 @@ export default class Machine {
|
|
|
140
140
|
}
|
|
141
141
|
return new Promise((resolve, reject) => {
|
|
142
142
|
const id = randombytes(20).toString('hex')
|
|
143
|
-
const onmessage = message => {
|
|
143
|
+
const onmessage = message => {
|
|
144
144
|
pubsub.unsubscribe(id, onmessage)
|
|
145
145
|
if (message?.error) reject(message.error)
|
|
146
146
|
else resolve(message)
|
package/src/transaction.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Protocol from "./protocol.js"
|
|
2
|
-
import
|
|
2
|
+
import MultiWallet from '@leofcoin/multi-wallet'
|
|
3
3
|
import {CodecHash} from '@leofcoin/codec-format-interface'
|
|
4
4
|
import bs32 from '@vandeurenglenn/base32'
|
|
5
5
|
import { TransactionMessage, BlockMessage } from "@leofcoin/messages"
|
|
@@ -26,7 +26,7 @@ export default class Transaction extends Protocol {
|
|
|
26
26
|
.map(async tx => {
|
|
27
27
|
tx = await new TransactionMessage(tx)
|
|
28
28
|
size += tx.encoded.length
|
|
29
|
-
if (!formatBytes(size).includes('MB') || formatBytes(size).includes('MB') && Number(formatBytes(size).split(' MB')[0]) <= 0.75) _transactions.push({...tx.decoded, hash: await tx.hash})
|
|
29
|
+
if (!formatBytes(size).includes('MB') || formatBytes(size).includes('MB') && Number(formatBytes(size).split(' MB')[0]) <= 0.75) _transactions.push({...tx.decoded, hash: await tx.hash()})
|
|
30
30
|
else resolve(_transactions)
|
|
31
31
|
}))
|
|
32
32
|
|
|
@@ -52,7 +52,7 @@ export default class Transaction extends Protocol {
|
|
|
52
52
|
*/
|
|
53
53
|
async promiseTransactionsContent(transactions) {
|
|
54
54
|
transactions = await Promise.all(transactions.map(tx => new Promise(async (resolve, reject) => {
|
|
55
|
-
resolve({ ...tx.decoded, hash: await tx.hash })
|
|
55
|
+
resolve({ ...tx.decoded, hash: await tx.hash() })
|
|
56
56
|
})))
|
|
57
57
|
|
|
58
58
|
return transactions
|
|
@@ -157,7 +157,7 @@ export default class Transaction extends Protocol {
|
|
|
157
157
|
let identity = await walletStore.get('identity')
|
|
158
158
|
identity = JSON.parse(new TextDecoder().decode(identity))
|
|
159
159
|
const wallet = new MultiWallet(peernet.network)
|
|
160
|
-
wallet.recover(identity.mnemonic)
|
|
160
|
+
await wallet.recover(identity.mnemonic)
|
|
161
161
|
const account = wallet.account(0).external(0)
|
|
162
162
|
transaction.signature = await this.#signTransaction(transaction, account)
|
|
163
163
|
transaction.signature = bs32.encode(transaction.signature)
|
|
@@ -209,23 +209,23 @@ export default class Transaction extends Protocol {
|
|
|
209
209
|
|
|
210
210
|
let data
|
|
211
211
|
const wait = () => new Promise(async (resolve, reject) => {
|
|
212
|
-
if (pubsub.subscribers[`transaction.completed.${await message.hash}`]) {
|
|
213
|
-
const result = pubsub.subscribers[`transaction.completed.${await message.hash}`].value
|
|
214
|
-
result.status === 'fulfilled' ? resolve(
|
|
212
|
+
if (pubsub.subscribers[`transaction.completed.${await message.hash()}`]) {
|
|
213
|
+
const result = pubsub.subscribers[`transaction.completed.${await message.hash()}`].value
|
|
214
|
+
result.status === 'fulfilled' ? resolve(result.hash) : reject({hash: result.hash, error: result.error})
|
|
215
215
|
} else {
|
|
216
216
|
const completed = async result => {
|
|
217
|
-
result.status === 'fulfilled' ? resolve(
|
|
217
|
+
result.status === 'fulfilled' ? resolve(result.hash) : reject({hash: result.hash, error: result.error})
|
|
218
218
|
|
|
219
219
|
setTimeout(async () => {
|
|
220
|
-
pubsub.unsubscribe(`transaction.completed.${await message.hash}`, completed)
|
|
220
|
+
pubsub.unsubscribe(`transaction.completed.${await message.hash()}`, completed)
|
|
221
221
|
}, 10_000)
|
|
222
222
|
}
|
|
223
|
-
pubsub.subscribe(`transaction.completed.${await message.hash}`, completed)
|
|
223
|
+
pubsub.subscribe(`transaction.completed.${await message.hash()}`, completed)
|
|
224
224
|
}
|
|
225
225
|
})
|
|
226
|
-
await transactionPoolStore.put(await message.hash, message.encoded)
|
|
226
|
+
await transactionPoolStore.put(await message.hash(), message.encoded)
|
|
227
227
|
peernet.publish('add-transaction', message.encoded)
|
|
228
|
-
return {hash: await message.hash, data, fee: await calculateFee(message.decoded), wait, message}
|
|
228
|
+
return {hash: await message.hash(), data, fee: await calculateFee(message.decoded), wait, message}
|
|
229
229
|
} catch (error) {
|
|
230
230
|
console.log(error)
|
|
231
231
|
throw error
|
package/test/chain.js
CHANGED
|
@@ -67,7 +67,7 @@ const job = async () => {
|
|
|
67
67
|
|
|
68
68
|
console.log(`${(new Date().getTime() - start) / 1000} s`);
|
|
69
69
|
|
|
70
|
-
balances = await chain.balances
|
|
70
|
+
let balances = await chain.balances
|
|
71
71
|
console.log(`balance for ${Object.keys(balances)[0]}:${chain.utils.formatUnits(balances[Object.keys(balances)[0]]).toString()}`);
|
|
72
72
|
console.log(`balance for ${Object.keys(balances)[1]}:${chain.utils.formatUnits(balances[Object.keys(balances)[1]]).toString()}`);
|
|
73
73
|
// return
|