Skip to content

Commit

Permalink
feat: send from example to wallet server
Browse files Browse the repository at this point in the history
  • Loading branch information
jowparks committed Sep 14, 2023
1 parent 7448b5b commit d9b39bc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 17 additions & 2 deletions example/src/Client/Client.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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]);
},
);
});
}
}
6 changes: 5 additions & 1 deletion example/src/Client/utils/AccountsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
6 changes: 6 additions & 0 deletions example/src/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}

0 comments on commit d9b39bc

Please sign in to comment.