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

fix: update wrappers #51

Merged
merged 3 commits into from
Oct 9, 2024
Merged
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
4 changes: 2 additions & 2 deletions wrappers/fedimint-go/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions wrappers/fedimint-go/pkg/fedimint/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 0 additions & 4 deletions wrappers/fedimint-go/pkg/fedimint/types/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,4 @@ type JoinResponse struct {
FederationIds []string `json:"federationIds"`
}

type DiscoverVersionRequest struct {
Threshold uint16 `json:"threshold"`
}

type FedimintResponse map[string]interface{}
5 changes: 1 addition & 4 deletions wrappers/fedimint-go/pkg/fedimint/types/modules/onchain.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
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
7 changes: 1 addition & 6 deletions wrappers/fedimint-ts/src/FedimintClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
MintValidateResponse,
OnchainAwaitDepositRequest,
OnchainAwaitDepositResponse,
OnchainDepositAddressRequest,
OnchainDepositAddressResponse,
OnchainWithdrawRequest,
OnchainWithdrawResponse,
Expand Down Expand Up @@ -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<OnchainDepositAddressResponse> => {
const request: OnchainDepositAddressRequest = { timeout };

return await this.postWithFederationId<OnchainDepositAddressResponse>(
"/onchain/deposit-address",
request,
{},
federationId
);
},
Expand Down
7 changes: 2 additions & 5 deletions wrappers/fedimint-ts/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -239,7 +236,7 @@ export interface MintEncodeNotesRequest {
}

export interface MintEncodeNotesResponse {
notes: string;
notesJson: string;
}

export interface MintReissueRequest {
Expand Down
16 changes: 10 additions & 6 deletions wrappers/fedimint-ts/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Loading