Demo TSS Contract

node v14.11.0
version: 1.0.1
endpointsharetweet
const cors = require('cors') const { json } = require('body-parser') const { Transaction, Networks, Asset, BASE_FEE, Operation } = require('stellar-sdk') const BigNumber = require('bignumber.js') const express = require('@runkit/tyvdh/express-endpoint/1.0.0') const sendError = require('@runkit/tyvdh/send-error/1.0.1') const app = express(exports) const XLM = Asset.native() app.use(cors()) app.use(json()) app.post('/', async (req, res) => { try { const {request, signers} = req.body const transaction = new Transaction(request.xdr, Networks.TESTNET) const op = transaction.operations[0] const amount = new BigNumber(op.amount) if ( transaction.operations.length > 1 || op.type !== 'payment' || !op.asset.equals(XLM) || amount.gt(100) ) throw 'Request rejected' for (const signer of signers) { const fee = new BigNumber(transaction._tx._attributes.fee) const op = Operation.payment({ destination: signer.turret, amount: signer.fee, asset: XLM }) transaction._tx._attributes.fee = fee.plus(BASE_FEE).toNumber() transaction._tx._attributes.operations.push(op) } res.send(transaction.toXDR()) } catch(err) { sendError(err, res) } })
Loading…

no comments

    sign in to comment