From ce151897edc757aca5e4358053e0d5342363abea Mon Sep 17 00:00:00 2001 From: "kody.low" Date: Wed, 9 Oct 2024 12:51:37 -0700 Subject: [PATCH 1/3] fix: update typescript wrapper --- wrappers/fedimint-ts/src/FedimintClient.ts | 7 +------ wrappers/fedimint-ts/src/types.ts | 7 ++----- wrappers/fedimint-ts/tests/test.ts | 16 ++++++++++------ 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/wrappers/fedimint-ts/src/FedimintClient.ts b/wrappers/fedimint-ts/src/FedimintClient.ts index 7a9606d..ac9145f 100644 --- a/wrappers/fedimint-ts/src/FedimintClient.ts +++ b/wrappers/fedimint-ts/src/FedimintClient.ts @@ -25,7 +25,6 @@ import { MintValidateResponse, OnchainAwaitDepositRequest, OnchainAwaitDepositResponse, - OnchainDepositAddressRequest, OnchainDepositAddressResponse, OnchainWithdrawRequest, OnchainWithdrawResponse, @@ -612,17 +611,13 @@ export class FedimintClient { public onchain = { /** * Creates a new bitcoin deposit address to peg in bitcoin to the federation. - * @param timeout - The number of seconds for the fedimint-clientd to watch for a deposit to the created address */ createDepositAddress: async ( - timeout: number, federationId?: string ): Promise => { - const request: OnchainDepositAddressRequest = { timeout }; - return await this.postWithFederationId( "/onchain/deposit-address", - request, + {}, federationId ); }, diff --git a/wrappers/fedimint-ts/src/types.ts b/wrappers/fedimint-ts/src/types.ts index 2961b51..cc8b7e7 100644 --- a/wrappers/fedimint-ts/src/types.ts +++ b/wrappers/fedimint-ts/src/types.ts @@ -54,13 +54,10 @@ export interface OperationOutput { outcome?: any; } -export interface OnchainDepositAddressRequest { - timeout: number; -} - export interface OnchainDepositAddressResponse { operationId: string; address: string; + tweakIdx: number; } export interface OnchainAwaitDepositRequest { @@ -239,7 +236,7 @@ export interface MintEncodeNotesRequest { } export interface MintEncodeNotesResponse { - notes: string; + notesJson: string; } export interface MintReissueRequest { diff --git a/wrappers/fedimint-ts/tests/test.ts b/wrappers/fedimint-ts/tests/test.ts index ad60439..3095ade 100644 --- a/wrappers/fedimint-ts/tests/test.ts +++ b/wrappers/fedimint-ts/tests/test.ts @@ -196,8 +196,8 @@ async function main() { logInputAndOutput({ notes: mintData.notes }, data); // `/v2/mint/encode-notes` logMethod("/v2/mint/encode-notes"); - data = await fedimintClient.mint.encodeNotes(data.notesJson); - logInputAndOutput({ notesJson: data.notesJson }, data); + const encodeData = await fedimintClient.mint.encodeNotes(data.notesJson); + logInputAndOutput({ notesJson: data.notesJson }, encodeData); // `/v2/mint/validate` logMethod("/v2/mint/validate"); data = await fedimintClient.mint.validate(mintData.notes); @@ -219,12 +219,16 @@ async function main() { // ONCHAIN METHODS // `/v2/onchain/deposit-address` logMethod("/v2/onchain/deposit-address"); - data = await fedimintClient.onchain.createDepositAddress(1000); - logInputAndOutput({ timeout: 1000 }, data); + data = await fedimintClient.onchain.createDepositAddress(); + logInputAndOutput({}, data); // `/v2/onchain/withdraw` logMethod("/v2/onchain/withdraw"); - data = await fedimintClient.onchain.withdraw(data.address, 1000); - logInputAndOutput({ address: data.address, amountSat: 1000 }, data); + const withdrawData = await fedimintClient.onchain.withdraw( + data.address, + 1000 + ); + console.log("Withdrew: ", withdrawData); + logInputAndOutput({ address: data.address, amountSat: 1000 }, withdrawData); // // `/v2/onchain/await-deposit` // logMethod("/v2/onchain/await-deposit"); // data = await fedimintClient.onchain.awaitDeposit(data.operationId); From eef0b65568ccaf78b84b273191a7eb6a78e383e0 Mon Sep 17 00:00:00 2001 From: "kody.low" Date: Wed, 9 Oct 2024 13:08:52 -0700 Subject: [PATCH 2/3] fix: update python wrappers --- wrappers/fedimint-py/AsyncFedimintClient.py | 16 ++++++++-------- wrappers/fedimint-py/FedimintClient.py | 12 ++++-------- wrappers/fedimint-py/models/mint.py | 4 ++-- wrappers/fedimint-py/models/onchain.py | 5 +---- wrappers/fedimint-py/test.py | 10 +++++----- wrappers/fedimint-py/test_async.py | 13 +++++-------- 6 files changed, 25 insertions(+), 35 deletions(-) diff --git a/wrappers/fedimint-py/AsyncFedimintClient.py b/wrappers/fedimint-py/AsyncFedimintClient.py index 2a6883d..db2e415 100644 --- a/wrappers/fedimint-py/AsyncFedimintClient.py +++ b/wrappers/fedimint-py/AsyncFedimintClient.py @@ -6,7 +6,6 @@ import atexit from models.common import ( - DiscoverVersionRequest, DiscoverVersionResponse, InfoResponse, ListOperationsRequest, @@ -29,7 +28,6 @@ from models.onchain import ( OnchainAwaitDepositRequest, OnchainAwaitDepositResponse, - OnchainDepositAddressRequest, OnchainDepositAddressResponse, OnchainWithdrawRequest, OnchainWithdrawResponse, @@ -185,9 +183,12 @@ async def config(self): # async def backup(self, request: BackupRequest, federationId: str = None): # return await self._post_with_id("/admin/backup", request, federationId) - async def discover_version(self, threshold: int) -> DiscoverVersionResponse: - request: DiscoverVersionRequest = {"threshold": threshold} - return await self._post("/admin/discover-version", request) + async def discover_version( + self, federation_id: str = None + ) -> DiscoverVersionResponse: + return await self._post_with_federation_id( + "/admin/discover-version", {}, federation_id + ) async def federation_ids(self): return await self._get("/admin/federation-ids") @@ -378,10 +379,9 @@ class Onchain: def __init__(self, client): self.client = client - async def create_deposit_address(self, timeout: int, federation_id: str = None): - request: OnchainDepositAddressRequest = {"timeout": timeout} + async def create_deposit_address(self, federation_id: str = None): return await self.client._post_with_federation_id( - "/onchain/deposit-address", request, federation_id + "/onchain/deposit-address", {}, federation_id ) async def await_deposit( diff --git a/wrappers/fedimint-py/FedimintClient.py b/wrappers/fedimint-py/FedimintClient.py index 9c0c520..ddaa5e7 100644 --- a/wrappers/fedimint-py/FedimintClient.py +++ b/wrappers/fedimint-py/FedimintClient.py @@ -4,7 +4,6 @@ import requests from models.common import ( - DiscoverVersionRequest, DiscoverVersionResponse, InfoResponse, ListOperationsRequest, @@ -26,7 +25,6 @@ from models.onchain import ( OnchainAwaitDepositRequest, OnchainAwaitDepositResponse, - OnchainDepositAddressRequest, OnchainWithdrawRequest, OnchainWithdrawResponse, ) @@ -157,9 +155,8 @@ def info(self) -> InfoResponse: def config(self): return self._get("/admin/config") - def discover_version(self, threshold: int) -> DiscoverVersionResponse: - request: DiscoverVersionRequest = {"threshold": threshold} - return self._post("/admin/discover-version", request) + def discover_version(self, federation_id: str = None) -> DiscoverVersionResponse: + return self._post_with_federation_id("/admin/discover-version", {}) def federation_ids(self): return self._get("/admin/federation-ids") @@ -343,10 +340,9 @@ class Onchain: def __init__(self, client): self.client = client - def create_deposit_address(self, timeout: int, federation_id: str = None): - request: OnchainDepositAddressRequest = {"timeout": timeout} + def create_deposit_address(self, federation_id: str = None): return self.client._post_with_federation_id( - "/onchain/deposit-address", request, federation_id + "/onchain/deposit-address", {}, federation_id ) def await_deposit( diff --git a/wrappers/fedimint-py/models/mint.py b/wrappers/fedimint-py/models/mint.py index 674dc76..e698bd5 100644 --- a/wrappers/fedimint-py/models/mint.py +++ b/wrappers/fedimint-py/models/mint.py @@ -17,7 +17,7 @@ class NotesJson(BaseModel): class MintDecodeNotesResponse(BaseModel): - notesJson: NotesJson + notes: NotesJson class MintEncodeNotesRequest(BaseModel): @@ -25,7 +25,7 @@ class MintEncodeNotesRequest(BaseModel): class MintEncodeNotesResponse(BaseModel): - notes: str + notesJson: str class MintReissueRequest(BaseModel): diff --git a/wrappers/fedimint-py/models/onchain.py b/wrappers/fedimint-py/models/onchain.py index 53d1482..e239eb5 100644 --- a/wrappers/fedimint-py/models/onchain.py +++ b/wrappers/fedimint-py/models/onchain.py @@ -2,13 +2,10 @@ from pydantic import BaseModel -class OnchainDepositAddressRequest(BaseModel): - timeout: int - - class OnchainDepositAddressResponse(BaseModel): operation_id: str address: str + tweak_idx: int class OnchainAwaitDepositRequest(BaseModel): diff --git a/wrappers/fedimint-py/test.py b/wrappers/fedimint-py/test.py index bc29fdf..9d75e54 100644 --- a/wrappers/fedimint-py/test.py +++ b/wrappers/fedimint-py/test.py @@ -45,7 +45,7 @@ def main(): log_input_and_output({}, data) log_method("/v2/admin/discover-version") - data = fedimint_client.discover_version(1) + data = fedimint_client.discover_version() log_input_and_output({}, data) log_method("/v2/admin/federation-ids") @@ -120,8 +120,8 @@ def main(): log_input_and_output({"notes": mint_data["notes"]}, data) log_method("/v2/mint/encode-notes") - data = fedimint_client.mint.encode_notes(data["notesJson"]) - log_input_and_output({"notesJson": data}, data) + encoded_data = fedimint_client.mint.encode_notes(data["notesJson"]) + log_input_and_output({"notesJson": data}, encoded_data) log_method("/v2/mint/validate") data = fedimint_client.mint.validate(mint_data["notes"]) @@ -145,8 +145,8 @@ def main(): # ONCHAIN METHODS log_method("/v2/onchain/deposit-address") - data = fedimint_client.onchain.create_deposit_address(1000) - log_input_and_output({"timeout": 1000}, data) + data = fedimint_client.onchain.create_deposit_address() + log_input_and_output({}, data) log_method("/v2/onchain/withdraw") withdraw_data = fedimint_client.onchain.withdraw(data["address"], 1000) log_input_and_output({"address": data["address"], "amountSat": 1000}, withdraw_data) diff --git a/wrappers/fedimint-py/test_async.py b/wrappers/fedimint-py/test_async.py index 75e5f1f..3ea6d3d 100644 --- a/wrappers/fedimint-py/test_async.py +++ b/wrappers/fedimint-py/test_async.py @@ -47,9 +47,7 @@ async def main(): # log_input_and_output({}, data) # `/v2/admin/discover-version` log_method("/v2/admin/discover-version") - data = await fedimint_client.discover_version( - 1 - ) # Assuming threshold is required, adjust as needed + data = await fedimint_client.discover_version() log_input_and_output({}, data) # `/v2/admin/federation-ids` log_method("/v2/admin/federation-ids") @@ -130,8 +128,8 @@ async def main(): log_input_and_output({"notes": mint_data["notes"]}, data) # `/v2/mint/encode-notes` log_method("/v2/mint/encode-notes") - data = await fedimint_client.mint.encode_notes(data["notesJson"]) - log_input_and_output({"notesJson": data}, data) + encoded_data = await fedimint_client.mint.encode_notes(data["notesJson"]) + log_input_and_output({"notesJson": data}, encoded_data) # `/v2/mint/validate` log_method("/v2/mint/validate") data = await fedimint_client.mint.validate(mint_data["notes"]) @@ -157,9 +155,8 @@ async def main(): # ONCHAIN METHODS # `/v2/onchain/deposit-address` log_method("/v2/onchain/deposit-address") - data = await fedimint_client.onchain.create_deposit_address(1000) - print("data: ", data) - log_input_and_output({"timeout": 1000}, data) + data = await fedimint_client.onchain.create_deposit_address() + log_input_and_output({}, data) # `/v2/onchain/withdraw` log_method("/v2/onchain/withdraw") withdraw_data = await fedimint_client.onchain.withdraw(data["address"], 1000) From 8fac0b6f5a406415f5ab0973d40edfa2ee36ccf5 Mon Sep 17 00:00:00 2001 From: "kody.low" Date: Wed, 9 Oct 2024 13:12:45 -0700 Subject: [PATCH 3/3] fix: update go wrapper --- wrappers/fedimint-go/cmd/main.go | 4 ++-- wrappers/fedimint-go/pkg/fedimint/client.go | 10 ++++------ wrappers/fedimint-go/pkg/fedimint/types/common.go | 4 ---- .../fedimint-go/pkg/fedimint/types/modules/onchain.go | 5 +---- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/wrappers/fedimint-go/cmd/main.go b/wrappers/fedimint-go/cmd/main.go index 25fba0f..2c8b7aa 100644 --- a/wrappers/fedimint-go/cmd/main.go +++ b/wrappers/fedimint-go/cmd/main.go @@ -87,7 +87,7 @@ func main() { // `/v2/admin/discover-version` logMethod("/v2/admin/discover-version") - discoverResponseData, err := fc.DiscoverVersion(1) + discoverResponseData, err := fc.DiscoverVersion(nil) if err != nil { fmt.Println("Error calling VERSION: ", err) return @@ -529,7 +529,7 @@ func main() { // `/v2/onchain/deposit-address` logMethod("/v2/onchain/deposit-address") - addr, err := fc.Onchain.CreateDepositAddress(1000, nil) + addr, err := fc.Onchain.CreateDepositAddress(nil) if err != nil { fmt.Println("Error calling CREATE_DEPOSIT_ADDRESS: ", err) return diff --git a/wrappers/fedimint-go/pkg/fedimint/client.go b/wrappers/fedimint-go/pkg/fedimint/client.go index 13d1f79..85b0ff9 100644 --- a/wrappers/fedimint-go/pkg/fedimint/client.go +++ b/wrappers/fedimint-go/pkg/fedimint/client.go @@ -239,9 +239,8 @@ func (fc *FedimintClient) Backup(metadata *types.BackupRequest, federationId *st return err } -func (fc *FedimintClient) DiscoverVersion(threshold uint16) (*types.FedimintResponse, error) { - request := types.DiscoverVersionRequest{Threshold: threshold} - resp, err := fc.post("/admin/discover-version", request) +func (fc *FedimintClient) DiscoverVersion(federationId *string) (*types.FedimintResponse, error) { + resp, err := fc.postWithFederationId("/admin/discover-version", nil, federationId) if err != nil { return nil, err } @@ -306,9 +305,8 @@ func (fc *FedimintClient) Join(inviteCode string, setActiveFederationId bool, us // Onchain // //////////// -func (onchain *OnchainModule) CreateDepositAddress(timeout int, federationId *string) (*modules.OnchainDepositAddressResponse, error) { - request := modules.OnchainDepositAddressRequest{Timeout: timeout} - resp, err := onchain.Client.postWithFederationId("/onchain/deposit-address", request, federationId) +func (onchain *OnchainModule) CreateDepositAddress(federationId *string) (*modules.OnchainDepositAddressResponse, error) { + resp, err := onchain.Client.postWithFederationId("/onchain/deposit-address", nil, federationId) if err != nil { return nil, err } diff --git a/wrappers/fedimint-go/pkg/fedimint/types/common.go b/wrappers/fedimint-go/pkg/fedimint/types/common.go index 2220db6..e135513 100644 --- a/wrappers/fedimint-go/pkg/fedimint/types/common.go +++ b/wrappers/fedimint-go/pkg/fedimint/types/common.go @@ -53,8 +53,4 @@ type JoinResponse struct { FederationIds []string `json:"federationIds"` } -type DiscoverVersionRequest struct { - Threshold uint16 `json:"threshold"` -} - type FedimintResponse map[string]interface{} diff --git a/wrappers/fedimint-go/pkg/fedimint/types/modules/onchain.go b/wrappers/fedimint-go/pkg/fedimint/types/modules/onchain.go index 6c64512..fb17428 100644 --- a/wrappers/fedimint-go/pkg/fedimint/types/modules/onchain.go +++ b/wrappers/fedimint-go/pkg/fedimint/types/modules/onchain.go @@ -1,12 +1,9 @@ package modules -type OnchainDepositAddressRequest struct { - Timeout int `json:"timeout"` -} - type OnchainDepositAddressResponse struct { OperationId string `json:"operationId"` Address string `json:"address"` + TweakIdx int `json:"tweakIdx"` } type OnchainAwaitDepositRequest struct {