Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rust wrapper #44

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
335 changes: 323 additions & 12 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["multimint", "fedimint-clientd", "fedimint-nwc"]
members = ["multimint", "fedimint-clientd", "fedimint-nwc", "wrappers/fedimint_clientd_rs"]
resolver = "2"

[workspace.package]
Expand Down
78 changes: 39 additions & 39 deletions wrappers/fedimint-ts/src/FedimintClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class FedimintClientBuilder {
this.baseUrl,
this.password,
this.activeFederationId,
this.activeGatewayId
this.activeGatewayId,
);

return client;
Expand All @@ -121,14 +121,14 @@ export class FedimintClient {
baseUrl: string,
password: string,
activeFederationId: string,
activeGatewayId: string = ""
activeGatewayId: string = "",
) {
this.baseUrl = baseUrl + "/v2";
this.password = password;
this.activeFederationId = activeFederationId;
this.activeGatewayId = activeGatewayId;
console.log(
"Fedimint Client initialized, must set activeGatewayId after intitalization to use lightning module methods or manually pass in gateways"
"Fedimint Client initialized, must set activeGatewayId after intitalization to use lightning module methods or manually pass in gateways",
);
}

Expand All @@ -153,7 +153,7 @@ export class FedimintClient {
});
} else {
console.log(
"Clearing active gateway id, must be set manually on lightning calls or setDefaultGatewayId to true"
"Clearing active gateway id, must be set manually on lightning calls or setDefaultGatewayId to true",
);
this.activeGatewayId = "";
}
Expand Down Expand Up @@ -196,7 +196,7 @@ export class FedimintClient {

if (!res.ok) {
throw new Error(
`GET request failed. Status: ${res.status}, Body: ${await res.text()}`
`GET request failed. Status: ${res.status}, Body: ${await res.text()}`,
);
}

Expand All @@ -222,7 +222,7 @@ export class FedimintClient {

if (!res.ok) {
throw new Error(
`POST request failed. Status: ${res.status}, Body: ${await res.text()}`
`POST request failed. Status: ${res.status}, Body: ${await res.text()}`,
);
}

Expand All @@ -241,7 +241,7 @@ export class FedimintClient {
private async postWithFederationId<T>(
endpoint: string,
body: any,
federationId?: string
federationId?: string,
): Promise<T> {
const effectiveFederationId = federationId || this.activeFederationId;

Expand All @@ -265,15 +265,15 @@ export class FedimintClient {
endpoint: string,
body: any,
gatewayId?: string,
federationId?: string
federationId?: string,
): Promise<T> {
try {
const effectiveGatewayId = gatewayId || this.activeGatewayId;
const effectiveFederationId = federationId || this.activeFederationId;

if (effectiveFederationId === "" || effectiveGatewayId === "") {
throw new Error(
"Must set active federation and gateway id before posting with them"
"Must set active federation and gateway id before posting with them",
);
}

Expand Down Expand Up @@ -323,13 +323,13 @@ export class FedimintClient {
* Returns the common API version to use to communicate with the federation and modules
*/
public async discoverVersion(
threshold?: number
threshold?: number,
): Promise<DiscoverVersionResponse> {
const request: DiscoverVersionRequest = threshold ? { threshold } : {};

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

Expand All @@ -340,14 +340,14 @@ export class FedimintClient {
*/
public async listOperations(
limit: number,
federationId?: string
federationId?: string,
): Promise<OperationOutput[]> {
const request: ListOperationsRequest = { limit };

return await this.postWithFederationId<OperationOutput[]>(
"/admin/list-operations",
request,
federationId
federationId,
);
}

Expand All @@ -372,7 +372,7 @@ export class FedimintClient {
inviteCode: string,
setActiveFederationId: boolean,
useDefaultGateway: boolean,
useManualSecret: boolean = false
useManualSecret: boolean = false,
): Promise<JoinResponse> {
const request: JoinRequest = { inviteCode, useManualSecret };

Expand All @@ -395,13 +395,13 @@ export class FedimintClient {
createInvoice: async (
request: LightningInvoiceRequest,
gatewayId?: string,
federationId?: string
federationId?: string,
): Promise<LightningInvoiceResponse> => {
return await this.postWithGatewayIdAndFederationId<LightningInvoiceResponse>(
"/ln/invoice",
request,
gatewayId,
federationId
federationId,
);
},

Expand All @@ -420,13 +420,13 @@ export class FedimintClient {
createInvoiceForPubkeyTweak: async (
request: LightningInvoiceExternalPubkeyTweakedRequest,
gatewayId?: string,
federationId?: string
federationId?: string,
): Promise<LightningInvoiceResponse> => {
return await this.postWithGatewayIdAndFederationId<LightningInvoiceExternalPubkeyTweakedResponse>(
"/ln/invoice-external-pubkey-tweaked",
request,
gatewayId,
federationId
federationId,
);
},

Expand All @@ -439,12 +439,12 @@ export class FedimintClient {
*/
claimPubkeyTweakReceives: async (
request: LightningClaimPubkeyTweakReceivesRequest,
federationId: string
federationId: string,
): Promise<LightningPaymentResponse> => {
return await this.postWithFederationId<LightningPaymentResponse>(
"/ln/claim-external-receive-tweaked",
request,
federationId
federationId,
);
},

Expand All @@ -455,14 +455,14 @@ export class FedimintClient {
*/
awaitInvoice: async (
operationId: string,
federationId?: string
federationId?: string,
): Promise<LightningPaymentResponse> => {
const request: LightningAwaitInvoiceRequest = { operationId };

return await this.postWithFederationId<LightningPaymentResponse>(
"/ln/await-invoice",
request,
federationId
federationId,
);
},

Expand All @@ -472,13 +472,13 @@ export class FedimintClient {
pay: async (
request: LightningPayRequest,
gatewayId?: string,
federationId?: string
federationId?: string,
): Promise<LightningPayResponse> => {
return await this.postWithGatewayIdAndFederationId<LightningPayResponse>(
"/ln/pay",
request,
gatewayId,
federationId
federationId,
);
},

Expand All @@ -503,23 +503,23 @@ export class FedimintClient {

return await this.post<MintDecodeNotesResponse>(
"/mint/decode-notes",
request
request,
);
},

/**
* Encodes json notes to hex encoded binary notes
*/
encodeNotes: async (
notesJson: NotesJson
notesJson: NotesJson,
): Promise<MintEncodeNotesResponse> => {
const request: MintEncodeNotesRequest = {
notesJsonStr: JSON.stringify(notesJson),
};

return await this.post<MintEncodeNotesResponse>(
"/mint/encode-notes",
request
request,
);
},

Expand All @@ -530,14 +530,14 @@ export class FedimintClient {
*/
reissue: async (
notes: string,
federationId?: string
federationId?: string,
): Promise<MintReissueResponse> => {
const request: MintReissueRequest = { notes };

return await this.postWithFederationId<MintReissueResponse>(
"/mint/reissue",
request,
federationId
federationId,
);
},

Expand All @@ -553,12 +553,12 @@ export class FedimintClient {
*/
spend: async (
request: MintSpendRequest,
federationId?: string
federationId?: string,
): Promise<MintSpendResponse> => {
return await this.postWithFederationId<MintSpendResponse>(
"/mint/spend",
request,
federationId
federationId,
);
},

Expand All @@ -567,14 +567,14 @@ export class FedimintClient {
*/
validate: async (
notes: string,
federationId?: string
federationId?: string,
): Promise<MintValidateResponse> => {
const request: MintValidateRequest = { notes };

return await this.postWithFederationId<MintValidateResponse>(
"/mint/validate",
request,
federationId
federationId,
);
},

Expand Down Expand Up @@ -616,14 +616,14 @@ export class FedimintClient {
*/
createDepositAddress: async (
timeout: number,
federationId?: string
federationId?: string,
): Promise<OnchainDepositAddressResponse> => {
const request: OnchainDepositAddressRequest = { timeout };

return await this.postWithFederationId<OnchainDepositAddressResponse>(
"/onchain/deposit-address",
request,
federationId
federationId,
);
},

Expand All @@ -635,14 +635,14 @@ export class FedimintClient {
*/
awaitDeposit: async (
operationId: string,
federationId?: string
federationId?: string,
): Promise<OnchainAwaitDepositResponse> => {
const request: OnchainAwaitDepositRequest = { operationId };

return await this.postWithFederationId<OnchainAwaitDepositResponse>(
"/onchain/await-deposit",
request,
federationId
federationId,
);
},

Expand All @@ -659,14 +659,14 @@ export class FedimintClient {
withdraw: async (
address: string,
amountSat: number | "all",
federationId?: string
federationId?: string,
): Promise<OnchainWithdrawResponse> => {
const request: OnchainWithdrawRequest = { address, amountSat };

return await this.postWithFederationId<OnchainWithdrawResponse>(
"/onchain/withdraw",
request,
federationId
federationId,
);
},
};
Expand Down
1 change: 1 addition & 0 deletions wrappers/fedimint_clientd_rs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
Loading
Loading