const addr1 = "foo"; const addr2 = "bar"; const fee = "fee"; const percentage = 0.01; async function deposit(account, amount, asset) { const response = (await fetch("http://127.0.0.1:8080/deposit", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ memo: "deposit", account, amount: amount.toString(), status: 'pending', asset, }) })); return response.json(); } async function trade(amount, asset, from, to) { const response = (await fetch("http://127.0.0.1:8080/tx", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ memo: "trade", debit: [ { account: from, amount: amount.toString(), asset, } ], credit: [ { account: to, amount: (amount * (1 - percentage)).toString(), asset, }, { account: fee, amount: (amount * percentage).toString(), asset, } ], status: 'pending', asset, }) })); return response.json(); } async function settle(id) { const response = (await fetch(`http://127.0.0.1:8080/${id}`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ status: "settled", memo: "trade", }) })); return response.json(); } async function test() { //const d = (await deposit(addr1, 100, "BTC")); //console.log(d); //console.log(await settle(d.id)); const t = await trade(10, "BTC", addr1, addr2); console.log(await settle(t.id)); } test()