node-info, fees requests, automatic foreign asset id replacements
This commit is contained in:
parent
591cdf88f3
commit
fb27aa8fbc
|
@ -22,14 +22,21 @@ const parser = createParser('/http-api/marketdata/marketdata.json', 20 * 1024)
|
|||
parser.eventEmitter.on('object', (obj) => {
|
||||
obj.Transfers.forEach((event) => {
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
event.Timestamp = Math.ceil(obj.Timestamp / 1000)
|
||||
event.Timestamp = Math.ceil(obj.Timestamp / 10 ** 6)
|
||||
transfers.push(event)
|
||||
})
|
||||
})
|
||||
|
||||
const app = express()
|
||||
app.use(express.json())
|
||||
app.use(express.urlencoded({ extended: true }))
|
||||
app.use('/api/v1/broadcast', (req, res, next) => {
|
||||
req.rawBody = ''
|
||||
req.on('data', (chunk) => {
|
||||
req.rawBody += chunk.toString()
|
||||
})
|
||||
req.on('end', () => {
|
||||
next()
|
||||
})
|
||||
})
|
||||
|
||||
function wrap(f) {
|
||||
return async (req, res) => {
|
||||
|
@ -97,19 +104,29 @@ async function handleAccount(req, res) {
|
|||
|
||||
async function handleAccountSequence(req, res) {
|
||||
const response = (await apiClient.get(`/api/v1/account/${req.params.account}`)).data
|
||||
res.send(response.sequence.toString())
|
||||
res.send({ sequence: response.sequence })
|
||||
}
|
||||
|
||||
async function handleNodeInfo(req, res) {
|
||||
const response = (await rpcClient.get('/status')).data
|
||||
res.send(response.result)
|
||||
}
|
||||
|
||||
async function handleFees(req, res) {
|
||||
const response = (await apiClient.get('/api/v1/fees')).data
|
||||
res.send(response)
|
||||
}
|
||||
|
||||
async function handleBroadcast(req, res) {
|
||||
if (req.query.sync !== 'true') {
|
||||
res.status(400).send('Async broadcast is not supported')
|
||||
} else {
|
||||
const response = (await rpcClient.get('/broadcast_tx_sync', {
|
||||
const response = await rpcClient.get('/broadcast_tx_sync', {
|
||||
params: {
|
||||
tx: req.body
|
||||
tx: `0x${req.rawBody}`
|
||||
}
|
||||
})).data
|
||||
res.send(response.result)
|
||||
})
|
||||
res.send([response.data.result])
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,8 +135,11 @@ app.get('/api/v1/time', wrap(handleTime))
|
|||
app.get('/api/v1/transactions', wrap(handleTransactions))
|
||||
app.get('/api/v1/account/:account', wrap(handleAccount))
|
||||
app.get('/api/v1/account/:account/sequence', wrap(handleAccountSequence))
|
||||
app.get('/api/v1/node-info', wrap(handleNodeInfo))
|
||||
app.get('/api/v1/fees', wrap(handleFees))
|
||||
app.post('/api/v1/broadcast', wrap(handleBroadcast))
|
||||
|
||||
app.listen(8000, () => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('Listening on port 8000')
|
||||
})
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
set -e
|
||||
|
||||
cd $(dirname "$0")
|
||||
|
||||
tbnbcli() {
|
||||
echo 12345678 | docker exec -i binance-testnet_node_1 ./tbnbcli $@ --from node0 --node http://node:26657 --chain-id Binance-Dev --json
|
||||
}
|
||||
|
@ -26,7 +28,16 @@ ISSUED_LOG=$(tbnbcli token issue --symbol DEV --total-supply 1000000000000 --tok
|
|||
TOKEN_SYMBOL=${ISSUED_LOG:(-8):7}
|
||||
echo "Issued $TOKEN_SYMBOL"
|
||||
|
||||
sed -i 's/FOREIGN_ASSET=.*$/FOREIGN_ASSET='"$TOKEN_SYMBOL"'/' ../test-services/binanceBalance/.env.development
|
||||
sed -i 's/FOREIGN_ASSET=.*$/FOREIGN_ASSET='"$TOKEN_SYMBOL"'/' ../test-services/binanceSend/.env.development
|
||||
sed -i 's/FOREIGN_ASSET=.*$/FOREIGN_ASSET='"$TOKEN_SYMBOL"'/' ../../demo/validator1/.env.development
|
||||
sed -i 's/FOREIGN_ASSET=.*$/FOREIGN_ASSET='"$TOKEN_SYMBOL"'/' ../../demo/validator2/.env.development
|
||||
sed -i 's/FOREIGN_ASSET=.*$/FOREIGN_ASSET='"$TOKEN_SYMBOL"'/' ../../demo/validator3/.env.development
|
||||
sed -i 's/FOREIGN_ASSET=.*$/FOREIGN_ASSET='"$TOKEN_SYMBOL"'/' ../../tests/.env
|
||||
|
||||
sleep 2
|
||||
|
||||
echo "Sending tokens to controlled address"
|
||||
tbnbcli token multi-send --transfers '[{"to":"tbnb1z7u9f8mcuwxanns9xa6qgjtlka0d392epc0m9x","amount":"1000000000000:BNB,1000000000000:'"$TOKEN_SYMBOL"'"}]'
|
||||
|
||||
sleep 2
|
Loading…
Reference in New Issue