Skip to content

Commit

Permalink
feat(walletd-libs): construct api and v2 api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Feb 4, 2025
1 parent 00c6291 commit ae1b758
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/hungry-monkeys-wonder.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/walletd-js': minor
'@siafoundation/walletd-react': minor
'@siafoundation/walletd-types': minor
---

Added construct APIs for both v1 and v2 transactions.
7 changes: 7 additions & 0 deletions .changeset/perfect-turtles-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/walletd-js': minor
'@siafoundation/walletd-react': minor
'@siafoundation/walletd-types': minor
---

Added the basis ChainIndex parameter to txpool broadcast API.
7 changes: 7 additions & 0 deletions .changeset/tricky-carrots-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/walletd-js': minor
'@siafoundation/walletd-react': minor
'@siafoundation/walletd-types': minor
---

Added the basis ChainIndex value to txpool transactions response.
4 changes: 2 additions & 2 deletions apps/walletd/contexts/addresses/dataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export function transformAddressesResponse(
const datum: AddressData = {
id: address,
address,
description: description,
spendPolicy: spendPolicy,
description,
spendPolicy,
metadata: (metadata || {}) as WalletAddressMetadata,
walletId,
onClick: () =>
Expand Down
3 changes: 2 additions & 1 deletion apps/walletd/contexts/addresses/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
WalletAddress,
WalletAddressMetadata,
} from '@siafoundation/walletd-types'
import { SpendPolicy } from '@siafoundation/types'

export type CellContext = {
siascanUrl: string
Expand All @@ -11,7 +12,7 @@ export type AddressData = {
id: string
address: string
description?: string
spendPolicy?: string
spendPolicy?: SpendPolicy
metadata: WalletAddressMetadata
walletId: string
raw?: WalletAddress
Expand Down
6 changes: 5 additions & 1 deletion libs/types/src/v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import {
SiafundOutput,
Signature,
StateElement,
UnlockConditions,
} from './core'

export type SpendPolicy = string
export type SpendPolicy = {
type: 'uc'
policy: UnlockConditions
}

export type V2SiacoinInput = {
parent: SiacoinElement
Expand Down
18 changes: 18 additions & 0 deletions libs/walletd-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ import {
WalletBalanceParams,
WalletBalancePayload,
WalletBalanceResponse,
WalletConstructV1TransactionParams,
WalletConstructV1TransactionPayload,
WalletConstructV1TransactionResponse,
WalletConstructV2TransactionParams,
WalletConstructV2TransactionPayload,
WalletConstructV2TransactionResponse,
WalletDeleteParams,
WalletDeletePayload,
WalletDeleteResponse,
Expand Down Expand Up @@ -93,6 +99,8 @@ import {
walletsIdAddressesAddrRoute,
walletsIdAddressesRoute,
walletsIdBalanceRoute,
walletsIdConstructTransactionRoute,
walletsIdConstructV2TransactionRoute,
walletsIdEventsRoute,
walletsIdEventsUnconfirmedRoute,
walletsIdFundRoute,
Expand Down Expand Up @@ -245,5 +253,15 @@ export function Walletd({ api, password }: { api: string; password?: string }) {
WalletReleasePayload,
WalletReleaseResponse
>(axios, 'post', walletsIdReleaseRoute),
walletConstructV1Transaction: buildRequestHandler<
WalletConstructV1TransactionParams,
WalletConstructV1TransactionPayload,
WalletConstructV1TransactionResponse
>(axios, 'post', walletsIdConstructTransactionRoute),
walletConstructV2Transaction: buildRequestHandler<
WalletConstructV2TransactionParams,
WalletConstructV2TransactionPayload,
WalletConstructV2TransactionResponse
>(axios, 'post', walletsIdConstructV2TransactionRoute),
}
}
28 changes: 28 additions & 0 deletions libs/walletd-react/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ import {
WalletAddressesResponse,
WalletBalanceParams,
WalletBalanceResponse,
WalletConstructV1TransactionParams,
WalletConstructV1TransactionPayload,
WalletConstructV1TransactionResponse,
WalletConstructV2TransactionParams,
WalletConstructV2TransactionPayload,
WalletConstructV2TransactionResponse,
WalletDeleteParams,
WalletDeletePayload,
WalletDeleteResponse,
Expand Down Expand Up @@ -92,6 +98,8 @@ import {
walletsIdAddressesAddrRoute,
walletsIdAddressesRoute,
walletsIdBalanceRoute,
walletsIdConstructTransactionRoute,
walletsIdConstructV2TransactionRoute,
walletsIdEventsRoute,
walletsIdEventsUnconfirmedRoute,
walletsIdFundRoute,
Expand Down Expand Up @@ -460,3 +468,23 @@ export function useWalletRelease(
) {
return usePostFunc({ ...args, route: walletsIdReleaseRoute })
}

export function useWalletConstructV1Transaction(
args?: HookArgsCallback<
WalletConstructV1TransactionParams,
WalletConstructV1TransactionPayload,
WalletConstructV1TransactionResponse
>
) {
return usePostFunc({ ...args, route: walletsIdConstructTransactionRoute })
}

export function useWalletConstructV2Transaction(
args?: HookArgsCallback<
WalletConstructV2TransactionParams,
WalletConstructV2TransactionPayload,
WalletConstructV2TransactionResponse
>
) {
return usePostFunc({ ...args, route: walletsIdConstructV2TransactionRoute })
}
41 changes: 41 additions & 0 deletions libs/walletd-types/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
Transaction,
V2Transaction,
WalletEvent,
SiacoinOutput,
Address,
SiafundOutput,
TransactionID,
} from '@siafoundation/types'
import { GatewayPeer, Wallet, WalletAddress, WalletMetadata } from './types'

Expand All @@ -37,6 +41,10 @@ export const walletsIdFundRoute = '/wallets/:id/fund'
export const walletsIdFundSfRoute = '/wallets/:id/fundsf'
export const walletsIdReserveRoute = '/wallets/:id/reserve'
export const walletsIdReleaseRoute = '/wallets/:id/release'
export const walletsIdConstructTransactionRoute =
'/wallets/:id/construct/transaction'
export const walletsIdConstructV2TransactionRoute =
'/wallets/:id/construct/v2/transaction'

// state

Expand Down Expand Up @@ -79,6 +87,7 @@ export type SyncerConnectResponse = never
export type TxPoolTransactionsParams = void
export type TxPoolTransactionsPayload = void
export type TxPoolTransactionsResponse = {
basis: ChainIndex
transactions: Transaction[]
v2transactions: V2Transaction[]
}
Expand All @@ -89,6 +98,7 @@ export type TxPoolFeeResponse = Currency

export type TxPoolBroadcastParams = void
export type TxPoolBroadcastPayload = {
basis: ChainIndex
transactions: Transaction[]
v2transactions: V2Transaction[]
}
Expand Down Expand Up @@ -226,3 +236,34 @@ export type WalletReleasePayload = {
siafundOutputs?: SiafundOutputID[]
}
export type WalletReleaseResponse = void

export type WalletConstructV1TransactionParams = {
id: string
}
export type WalletConstructV1TransactionPayload = {
siacoins?: SiacoinOutput[]
siafunds?: SiafundOutput[]
changeAddress: Address
}

export type WalletConstructV1TransactionResponse = {
basis: ChainIndex
id: TransactionID
transaction: Transaction
estimatedFee: Currency
}

export type WalletConstructV2TransactionParams = {
id: string
}
export type WalletConstructV2TransactionPayload = {
siacoins?: SiacoinOutput[]
siafunds?: SiafundOutput[]
changeAddress: Address
}
export type WalletConstructV2TransactionResponse = {
basis: ChainIndex
id: TransactionID
transaction: V2Transaction
estimatedFee: Currency
}

0 comments on commit ae1b758

Please sign in to comment.