From d9b39bcfba8b09c3a7b7ff7366123b9c93c89646 Mon Sep 17 00:00:00 2001 From: Joe Date: Thu, 14 Sep 2023 12:03:32 -0700 Subject: [PATCH] feat: send from example to wallet server --- README.md | 32 +++++++++++++++++++++ example/src/Client/Client.ts | 19 ++++++++++-- example/src/Client/utils/AccountsManager.ts | 6 +++- example/src/send.ts | 6 ++++ 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1b6693d..82e40c1 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,38 @@ The wallet server makes it possible to build/run a fully private light wallet (on nearly any device) without having to run a ironfish node locally. The implementation is a gRPC caching server that interacts with an [ironfish](https://github.com/iron-fish/ironfish) node to provide a cached interface for light wallet clients. Running this server allows clients to use a generated gRPC client to make typesafe calls to the client server to request "LightBlocks". These blocks are minimal represenations of Iron Fish network blocks. We have included an [example light wallet client](example/README.md) implementation in this repo. +## Quick start local setup + +### Terminal Session 1: Setting Up the Ironfish Node + +- Install and run Ironfish node: + - `npm install -g ironfish` + - `ironfish start --rpc.tcp` +- This node must be synced before starting terminal 2 + +### Terminal Session 2: Running the Wallet Server + +- Make sure you have a `.env` in root dir (or env vars), see [.env.example](./.env.example) for example + - `NODE_HOST` set to `localhost` + - `NODE_AUTH_TOKEN` set to `cat ~/.ironfish/internal.json | jq -r '.rpcAuthToken'` +- Run wallet server: from this repo root, run: + - `yarn` + - `yarn start` +- Wait for wallet to sync before starting terminal session 3 + +### Terminal Session 3: Example Wallet Client + +- change directory to `example/` +- If running wallet-server +- make sure `.env` exists, see [example/.env.example](./example/.env.example) for example +- Install dependencies + - `yarn` +- To see account balance + - `yarn dev` +- To send a transaction + - `yarn dev send assetId=51f33a2f14f92735e562dc658a5639279ddca3d5079a6d1242b2a588a9cbf44c toPublicAddress=c016b357465f41fcfd896eb6b878bcd865726779096d208f64e54347df9b46c7 amount=1 memo=test fee=1` +- wait for syncing of wallet to occur, this may take some time + ## Account balances for any account Requesting blocks via the `getBlockRange` endpoint provides all transactions that have occurred on the network. The `output`s provide what notes have been created in a given transaction, the `spend`s (the important piece being the nullifiers) tell you which notes have been spent in a transaction. Given these two pieces of information, you can constructed the balance for any account for which you have the spending key. diff --git a/example/src/Client/Client.ts b/example/src/Client/Client.ts index ae43c04..7bf97b1 100644 --- a/example/src/Client/Client.ts +++ b/example/src/Client/Client.ts @@ -1,5 +1,9 @@ -import { credentials } from "@grpc/grpc-js"; -import { LightStreamerClient } from "../../../src/models/lightstreamer"; +import { ServiceError, credentials } from "@grpc/grpc-js"; +import { + LightStreamerClient, + SendResponse, + Transaction, +} from "../../../src/models/lightstreamer"; import { BlockProcessor } from "./utils/BlockProcessor"; import { AccountData, AccountsManager } from "./utils/AccountsManager"; import { BlockCache } from "./utils/BlockCache"; @@ -167,4 +171,15 @@ export class Client { } return notesToSpend; } + + public async sendTransaction(transaction: Buffer) { + return new Promise<[ServiceError | null, SendResponse]>((res) => { + client.sendTransaction( + Transaction.create({ data: transaction }), + (error, result) => { + res([error, result]); + }, + ); + }); + } } diff --git a/example/src/Client/utils/AccountsManager.ts b/example/src/Client/utils/AccountsManager.ts index 82ecbaa..c9657c8 100644 --- a/example/src/Client/utils/AccountsManager.ts +++ b/example/src/Client/utils/AccountsManager.ts @@ -74,7 +74,11 @@ export class AccountsManager { if (!sequenceKey) { return; } - console.log(`Processing accounts for block ${sequenceKey}`); + logThrottled( + `Processing accounts for block ${sequenceKey}`, + 1000, + sequenceKey, + ); this._processBlockForTransactions(value); }) .on("end", () => { diff --git a/example/src/send.ts b/example/src/send.ts index 1d4c1da..1adb6b8 100644 --- a/example/src/send.ts +++ b/example/src/send.ts @@ -31,4 +31,10 @@ export async function send( console.log("Posted transaction:"); console.log(posted.toString("hex")); + + const [error, result] = await client.sendTransaction(posted); + if (error) { + console.error(error); + } + console.log(`Sent transaction, result: ${JSON.stringify(result)}`); }