Skip to content

Commit

Permalink
fix: v0.3 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed Mar 21, 2024
1 parent ed42933 commit 8f93076
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 266 deletions.
2 changes: 1 addition & 1 deletion fedimint-clientd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ fn fedimint_v2_rest() -> Router<AppState> {
.route("/backup", post(fedimint::admin::backup::handle_rest))
.route(
"/discover-version",
get(fedimint::admin::discover_version::handle_rest),
post(fedimint::admin::discover_version::handle_rest),
)
.route(
"/federation-ids",
Expand Down
32 changes: 22 additions & 10 deletions wrappers/fedimint-ts/FedimintClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import type {
ListOperationsRequest,
FederationIdsResponse,
OperationOutput,
} from "./types/common";
DiscoverVersionRequest,
DiscoverVersionResponse,
JoinRequest,
} from "./types";
import type {
AwaitInvoiceRequest,
Gateway,
LnInvoiceRequest,
LnInvoiceResponse,
LnPayRequest,
LnPayResponse,
} from "./types/modules/ln";
} from "./types";
import type {
CombineRequest,
CombineResponse,
Expand All @@ -24,15 +27,15 @@ import type {
SplitResponse,
ValidateRequest,
ValidateResponse,
} from "./types/modules/mint";
} from "./types";
import type {
AwaitDepositRequest,
AwaitDepositResponse,
DepositAddressRequest,
DepositAddressResponse,
WithdrawRequest,
WithdrawResponse,
} from "./types/modules/wallet";
} from "./types";

type FedimintResponse<T> = Promise<T>;

Expand Down Expand Up @@ -186,8 +189,16 @@ class FedimintClient {
/**
* Returns the API version to use to communicate with the federation
*/
public async discoverVersion(): FedimintResponse<string> {
return this.get<string>("/admin/discover-version");
public async discoverVersion(
threshold?: number
): FedimintResponse<DiscoverVersionResponse> {
const request: DiscoverVersionRequest = threshold ? { threshold } : {};
console.log("request", request);

return this.post<DiscoverVersionResponse>(
"/admin/discover-version",
request
);
}

/**
Expand All @@ -209,11 +220,12 @@ class FedimintClient {
* Returns an array of federation IDs that the client is now connected to
*/
public async join(
inviteCode: string
inviteCode: string,
useManualSecret: boolean = false
): FedimintResponse<FederationIdsResponse> {
return await this.post<FederationIdsResponse>("/admin/join", {
inviteCode,
});
const request: JoinRequest = { inviteCode, useManualSecret };

return await this.post<FederationIdsResponse>("/admin/join", request);
}

/**
Expand Down
21 changes: 11 additions & 10 deletions wrappers/fedimint-ts/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ dotenv.config();

const logMethod = (method: string) => {
console.log("--------------------");
console.log(`\nMethod: ${method}`);
console.log(`Method: ${method}`);
};

const logInputAndOutput = (input: any, output: any) => {
console.log("Input: ", input);
console.log("Output: ", output);
console.log("--------------------\n\n");
console.log("--------------------");
};

async function buildTestClient() {
const baseUrl = process.env.BASE_URL || "http://127.0.0.1:3333";
const password = process.env.PASSWORD || "password";
const builder = new FedimintClientBuilder();
builder.setBaseUrl(baseUrl).setPassword(password).setActiveFederationId(
"412d2a9338ebeee5957382eb06eac07fa5235087b5a7d5d0a6e18c635394e9ed" // Fedi Alpha Mutinynet
"15db8cb4f1ec8e484d73b889372bec94812580f929e8148b7437d359af422cd3" // Fedi Alpha Mutinynet
);

return await builder.build();
Expand Down Expand Up @@ -109,17 +109,18 @@ async function main() {
logInputAndOutput({ notesVec }, data);

// ONCHAIN METHODS
// // `/v2/onchain/deposit-address`
// logMethod("/v2/onchain/deposit-address");
// data = await fedimintClient.onchain.createDepositAddress(1000);
// logInputAndOutput({ timeout: 1000 }, data);
// `/v2/onchain/deposit-address`
logMethod("/v2/onchain/deposit-address");
data = await fedimintClient.onchain.createDepositAddress(1000);
logInputAndOutput({ timeout: 1000 }, data);
// `/v2/onchain/withdraw`
logMethod("/v2/onchain/withdraw");
data = await fedimintClient.onchain.withdraw(data.address, 1000);
logInputAndOutput({ address: data.address, amountMsat: 1000 }, data);
// // `/v2/onchain/await-deposit`
// logMethod("/v2/onchain/await-deposit");
// data = await fedimintClient.onchain.awaitDeposit(data.operationId);
// logInputAndOutput({ operationId: data.operationId }, data);
// // `/v2/onchain/withdraw`
// logMethod("/v2/onchain/withdraw");
// data = await fedimintClient.
}

main().catch(console.error);
85 changes: 30 additions & 55 deletions wrappers/fedimint-ts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@ interface InfoResponse {
denominationsMsat: TieredSummary;
}

interface FederationIdsResponse {
federationIds: string[];
}

interface DiscoverVersionRequest {
threshold?: number;
}

interface DiscoverVersionResponse {
[federationId: string]: any;
}

interface JoinRequest {
inviteCode: string;
useManualSecret: boolean;
}

interface BackupRequest {
metadata: { [key: string]: string };
}
Expand Down Expand Up @@ -100,7 +117,6 @@ interface AwaitInvoiceRequest {
interface LnPayRequest {
paymentInfo: string;
amountMsat?: number;
finishInBackground: boolean;
lnurlComment?: string;
}

Expand All @@ -124,59 +140,14 @@ interface SwitchGatewayRequest {
gatewayId: string;
}

interface FederationIdPrefix {
0: number; // Assuming u8 is equivalent to number in TypeScript
1: number;
2: number;
3: number;
}
type FederationIdPrefix = string;

interface TieredMulti<T> {
[amount: number]: T[]; // Assuming Amount is equivalent to number in TypeScript
}

interface Signature {
0: G1Affine;
}

interface G1Affine {
x: Fp;
y: Fp;
infinity: Choice;
}

interface Fp {
0: number[]; // Assuming u64 is equivalent to number in TypeScript
}

interface Choice {
0: number; // Assuming u8 is equivalent to number in TypeScript
}

interface KeyPair {
0: number[]; // Assuming c_uchar is equivalent to number in TypeScript
}

interface OOBNotesData {
Notes?: TieredMulti<SpendableNote>;
FederationIdPrefix?: FederationIdPrefix;
Default?: {
variant: number; // Assuming u64 is equivalent to number in TypeScript
bytes: number[]; // Assuming Vec<u8> is equivalent to number[] in TypeScript
};
}

interface OOBNotes {
0: OOBNotesData[];
}

interface SpendableNote {
signature: Signature;
spendKey: KeyPair;
[amount: number]: T[];
}

interface ReissueRequest {
notes: OOBNotes;
notes: string;
}

interface ReissueResponse {
Expand All @@ -191,37 +162,41 @@ interface SpendRequest {

interface SpendResponse {
operation: string;
notes: OOBNotes;
notes: string;
}

interface ValidateRequest {
notes: OOBNotes;
notes: string;
}

interface ValidateResponse {
amountMsat: number;
}

interface SplitRequest {
notes: OOBNotes;
notes: string;
}

interface SplitResponse {
notes: Record<number, OOBNotes>;
notes: Record<number, string>;
}

interface CombineRequest {
notes: OOBNotes[];
notesVec: string[];
}

interface CombineResponse {
notes: OOBNotes;
notes: string;
}

export type {
Tiered,
TieredSummary,
InfoResponse,
FederationIdsResponse,
DiscoverVersionRequest,
DiscoverVersionResponse,
JoinRequest,
BackupRequest,
ListOperationsRequest,
OperationOutput,
Expand Down
47 changes: 0 additions & 47 deletions wrappers/fedimint-ts/types/common.ts

This file was deleted.

51 changes: 0 additions & 51 deletions wrappers/fedimint-ts/types/modules/ln.ts

This file was deleted.

Loading

0 comments on commit 8f93076

Please sign in to comment.