Skip to content

Commit

Permalink
fix: update python wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodylow committed Oct 9, 2024
1 parent 1746851 commit 59bf8fa
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 35 deletions.
16 changes: 8 additions & 8 deletions wrappers/fedimint-py/AsyncFedimintClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import atexit

from models.common import (
DiscoverVersionRequest,
DiscoverVersionResponse,
InfoResponse,
ListOperationsRequest,
Expand All @@ -29,7 +28,6 @@
from models.onchain import (
OnchainAwaitDepositRequest,
OnchainAwaitDepositResponse,
OnchainDepositAddressRequest,
OnchainDepositAddressResponse,
OnchainWithdrawRequest,
OnchainWithdrawResponse,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down
12 changes: 4 additions & 8 deletions wrappers/fedimint-py/FedimintClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import requests

from models.common import (
DiscoverVersionRequest,
DiscoverVersionResponse,
InfoResponse,
ListOperationsRequest,
Expand All @@ -26,7 +25,6 @@
from models.onchain import (
OnchainAwaitDepositRequest,
OnchainAwaitDepositResponse,
OnchainDepositAddressRequest,
OnchainWithdrawRequest,
OnchainWithdrawResponse,
)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions wrappers/fedimint-py/models/mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class NotesJson(BaseModel):


class MintDecodeNotesResponse(BaseModel):
notesJson: NotesJson
notes: NotesJson


class MintEncodeNotesRequest(BaseModel):
notesJsonStr: str


class MintEncodeNotesResponse(BaseModel):
notes: str
notesJson: str


class MintReissueRequest(BaseModel):
Expand Down
5 changes: 1 addition & 4 deletions wrappers/fedimint-py/models/onchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 5 additions & 5 deletions wrappers/fedimint-py/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"])
Expand All @@ -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)
Expand Down
13 changes: 5 additions & 8 deletions wrappers/fedimint-py/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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"])
Expand All @@ -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)
Expand Down

0 comments on commit 59bf8fa

Please sign in to comment.