Implemented /api/v1/tx mock
This commit is contained in:
parent
64e4d5e9f1
commit
e832874891
|
@ -10,5 +10,9 @@
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10.6.0"
|
"node": ">=10.6.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@binance-chain/javascript-sdk": "^2.16.1",
|
||||||
|
"@tendermint/amino-js": "^0.4.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,20 +16,3 @@ RUN ./fullnode/testnet/${BNC_VERSION}/linux/bnbchaind testnet --acc-prefix tbnb
|
||||||
|
|
||||||
RUN sed -i "s/publishTransfer = false/publishTransfer = true/" ./mytestnet/node0/gaiad/config/app.toml && \
|
RUN sed -i "s/publishTransfer = false/publishTransfer = true/" ./mytestnet/node0/gaiad/config/app.toml && \
|
||||||
sed -i "s/publishLocal = false/publishLocal = true/" ./mytestnet/node0/gaiad/config/app.toml
|
sed -i "s/publishLocal = false/publishLocal = true/" ./mytestnet/node0/gaiad/config/app.toml
|
||||||
|
|
||||||
#echo 12345678 | docker exec -i 5f6f653730442d81b6e34a82ac3dc8a82f071c1eec130bc09a0dca803ad00bd2 ./tbnbcli send --to tbnb1efjg7xt98t67ql2cmwjc5860lgayet9l8m55ym --amount 100:BNB --from node0 --chain-id Binance-Dev --json
|
|
||||||
|
|
||||||
FROM alpine:3.9.4
|
|
||||||
|
|
||||||
ARG BNC_VERSION=0.6.2
|
|
||||||
|
|
||||||
WORKDIR /bnc
|
|
||||||
|
|
||||||
COPY --from=build /binaries/fullnode/testnet/${BNC_VERSION}/linux/bnbchaind ./
|
|
||||||
COPY --from=build /binaries/cli/testnet/${BNC_VERSION}/linux/tbnbcli ./
|
|
||||||
COPY --from=build /binaries/mytestnet/node0/gaiacli /root/.bnbcli
|
|
||||||
COPY --from=build /binaries/mytestnet/node0/gaiad /root/.bnbchaind
|
|
||||||
|
|
||||||
EXPOSE 26657
|
|
||||||
|
|
||||||
ENTRYPOINT ["./bnbchaind", "start"]
|
|
|
@ -1,7 +1,11 @@
|
||||||
FROM node:10.16.0-alpine
|
FROM node:10.16.0-alpine
|
||||||
|
|
||||||
|
ARG BNC_VERSION=0.6.2
|
||||||
|
|
||||||
WORKDIR /api-server
|
WORKDIR /api-server
|
||||||
|
|
||||||
|
COPY --from=testnet-binaries /binaries/cli/testnet/${BNC_VERSION}/linux/tbnbcli ./
|
||||||
|
|
||||||
COPY ./package.json ./
|
COPY ./package.json ./
|
||||||
|
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
|
@ -1,10 +1,73 @@
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const express = require('express')
|
const express = require('express')
|
||||||
|
const axios = require('axios')
|
||||||
|
const { execSync } = require('child_process')
|
||||||
|
|
||||||
|
const rpcClient = axios.create({
|
||||||
|
baseURL: process.env.FOREIGN_RPC_URL,
|
||||||
|
timeout: 10000
|
||||||
|
})
|
||||||
|
|
||||||
|
async function delay(ms) {
|
||||||
|
await new Promise((res) => setTimeout(res, ms))
|
||||||
|
}
|
||||||
|
|
||||||
|
async function retry(getPromise, n = -1, sleep = 3000) {
|
||||||
|
while (n) {
|
||||||
|
try {
|
||||||
|
return await getPromise()
|
||||||
|
} catch (e) {
|
||||||
|
console.debug(`Promise failed, retrying, ${n - 1} attempts left`)
|
||||||
|
await delay(sleep)
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
n -= 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendRpcRequest(subUrl, method, params) {
|
||||||
|
console.trace(`Request to ${subUrl}, method ${method}, params `, params)
|
||||||
|
const response = await retry(() => rpcClient.post(subUrl, {
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
method,
|
||||||
|
params,
|
||||||
|
id: 1
|
||||||
|
}))
|
||||||
|
console.trace('Response, ', response.data)
|
||||||
|
return response.data
|
||||||
|
}
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
|
|
||||||
app.get('/', (req, res) => {
|
// GET
|
||||||
res.send(fs.readFileSync('./marketdata/marketdata.json').toString())
|
// /api/v1/tx/:hash
|
||||||
|
// /api/v1/time
|
||||||
|
// /api/v1/transactions
|
||||||
|
// ?address=a&side=RECEIVE&txAsset=FOREIGN_ASSET&txType=TRANSFER&startTime=111&endTime=222
|
||||||
|
// /api/v1/account/:account
|
||||||
|
// /api/v1/account/:account/sequence
|
||||||
|
// POST
|
||||||
|
// /api/v1/broadcast?sync=true
|
||||||
|
|
||||||
|
app.get('/api/v1/tx/:hash', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const {
|
||||||
|
tx, hash, height, result
|
||||||
|
} = JSON.parse(
|
||||||
|
execSync(`./tbnbcli tx ${req.params.hash} --node "http://node:26657" --chain-id Binance-Dev`)
|
||||||
|
)
|
||||||
|
res.send({
|
||||||
|
code: 0,
|
||||||
|
hash,
|
||||||
|
height,
|
||||||
|
log: result.log,
|
||||||
|
ok: true,
|
||||||
|
tx
|
||||||
|
})
|
||||||
|
} catch (e) {
|
||||||
|
res.status(404).end()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
app.listen(8000, () => {
|
app.listen(8000, () => {
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
version: '3.0'
|
version: '3.0'
|
||||||
services:
|
services:
|
||||||
testnet:
|
node:
|
||||||
build: ./testnet
|
build: node
|
||||||
image: bnc-testnet
|
image: bnc-testnet
|
||||||
networks:
|
networks:
|
||||||
- binance_rpc_net
|
- binance_rpc_net
|
||||||
|
ports:
|
||||||
|
- '26657:26657'
|
||||||
volumes:
|
volumes:
|
||||||
- 'marketdata:/root/.bnbchaind/marketdata'
|
- 'marketdata:/root/.bnbchaind/marketdata'
|
||||||
api-server:
|
api-server:
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#echo 12345678 | docker exec -i 5f6f653730442d81b6e34a82ac3dc8a82f071c1eec130bc09a0dca803ad00bd2 ./tbnbcli send --to tbnb1efjg7xt98t67ql2cmwjc5860lgayet9l8m55ym --amount 100:BNB --from node0 --chain-id Binance-Dev --json
|
||||||
|
FROM alpine:3.9.4
|
||||||
|
|
||||||
|
ARG BNC_VERSION=0.6.2
|
||||||
|
|
||||||
|
WORKDIR /bnc
|
||||||
|
|
||||||
|
COPY --from=testnet-binaries /binaries/fullnode/testnet/${BNC_VERSION}/linux/bnbchaind ./
|
||||||
|
COPY --from=testnet-binaries /binaries/cli/testnet/${BNC_VERSION}/linux/tbnbcli ./
|
||||||
|
COPY --from=testnet-binaries /binaries/mytestnet/node0/gaiacli /root/.bnbcli
|
||||||
|
COPY --from=testnet-binaries /binaries/mytestnet/node0/gaiad /root/.bnbchaind
|
||||||
|
|
||||||
|
EXPOSE 26657
|
||||||
|
|
||||||
|
ENTRYPOINT ["./bnbchaind", "start"]
|
|
@ -3,4 +3,7 @@
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
docker network create binance_net > /dev/null 2>&1 || true
|
docker network create binance_net > /dev/null 2>&1 || true
|
||||||
|
|
||||||
|
docker build -t testnet-binaries .
|
||||||
|
|
||||||
docker-compose up --build
|
docker-compose up --build
|
||||||
|
|
Loading…
Reference in New Issue