From a2ee99ba552d12bbeb6398512c5d4a7a4ade19d7 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Tue, 9 Jan 2024 23:48:31 -0600 Subject: [PATCH] feat(ag-trade): get local node info using cosmos-fetch endo plugin --- packages/ag-trade/Makefile | 18 ++++++++++++++++++ packages/ag-trade/src/net-local.js | 22 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 packages/ag-trade/Makefile create mode 100644 packages/ag-trade/src/net-local.js diff --git a/packages/ag-trade/Makefile b/packages/ag-trade/Makefile new file mode 100644 index 0000000..68f9f55 --- /dev/null +++ b/packages/ag-trade/Makefile @@ -0,0 +1,18 @@ +STATE=$(shell endo where state) +PET=$(STATE)/pet-store + +where: + @echo state: $(STATE) + +node-info: $(PET)/local + endo eval "E(local.lcd).getJSON('/node_info').then(i => i.node_info)" local + +$(PET)/local: src/net-local.js $(PET)/cosmos-fetch + endo make src/net-local.js -n local -p cosmos-fetch + +$(PET)/cosmos-fetch: src/cosmosFetch.js + @echo ++ install cosmos fetch plugin + endo make --UNSAFE src/cosmosFetch.js -n cosmos-fetch + +clean: + endo reset diff --git a/packages/ag-trade/src/net-local.js b/packages/ag-trade/src/net-local.js new file mode 100644 index 0000000..e074f6d --- /dev/null +++ b/packages/ag-trade/src/net-local.js @@ -0,0 +1,22 @@ +/** + * Usage: + * $ endo make --UNSAFE src/cosmosFetch.js -n cosmos-fetch + * Object [Alleged: CosmosFetch] {} + * $ endo make test/net-local.js -n local -p cosmos-fetch + * { lcd: Object [Alleged: LCD] {}, rpc: Object [Alleged: RpcClient] {} } + */ +import { E } from '@endo/far'; + +const loc = { + lcd: 'http://localhost:1317', + rpc: 'http://localhost:26657', +}; + +export const make = async net => { + const [lcd, rpc] = await Promise.all([ + E(net).makeLCDClient(loc.lcd), + E(net).makeRPCClient(loc.rpc), + ]); + + return harden({ lcd, rpc }); +};