-
Notifications
You must be signed in to change notification settings - Fork 0
/
broadcast.mjs
48 lines (37 loc) · 1.25 KB
/
broadcast.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import golos from 'golos-lib-js'
import { OTYPES, ungolosifyId } from './ids.mjs'
export async function broadcastTransactionSynchronous(args) {
const [ trx ] = args
console.log('broadcastTransactionSynchronous' , JSON.stringify(trx))
const res = await golos.api.broadcastTransactionSynchronousAsync(trx)
const operation_results = []
for (let op of trx.operations) {
if (op[0] === 5 || op[0] === 'limit_order_create') {
// TODO: But if called with returnOrderId = False, it should have another format...
const opr = []
opr.push(5)
const orderid = await ungolosifyId(OTYPES.limit_order, op[1].owner + '|' + op[1].orderid.toString())
opr.push(orderid)
operation_results.push(opr)
}
}
trx.operation_results = operation_results
res.trx = trx
console.log('broadcastTransactionSynchronous result', res)
return res
}
export async function broadcastTransaction(args) {
const [ trx ] = args
console.log('broadcastTransaction' , JSON.stringify(trx))
let res
try {
res = await golos.api.broadcastTransactionAsync(trx)
console.log('broadcastTransaction result', res)
return res
} catch (err) {
// TODO but actually not works, bot still working
console.log('broadcastTransaction err', err)
return err.payload
}
return res
}