diff --git a/.changeset/hungry-monkeys-wonder.md b/.changeset/hungry-monkeys-wonder.md new file mode 100644 index 000000000..dbf6aa213 --- /dev/null +++ b/.changeset/hungry-monkeys-wonder.md @@ -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. diff --git a/.changeset/perfect-turtles-kiss.md b/.changeset/perfect-turtles-kiss.md new file mode 100644 index 000000000..75a64a9a0 --- /dev/null +++ b/.changeset/perfect-turtles-kiss.md @@ -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. diff --git a/.changeset/tricky-carrots-deny.md b/.changeset/tricky-carrots-deny.md new file mode 100644 index 000000000..6fba0fa3f --- /dev/null +++ b/.changeset/tricky-carrots-deny.md @@ -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. diff --git a/libs/types/src/v2.ts b/libs/types/src/v2.ts index 3d613a5a2..0b5c17d9a 100644 --- a/libs/types/src/v2.ts +++ b/libs/types/src/v2.ts @@ -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 diff --git a/libs/walletd-js/src/index.ts b/libs/walletd-js/src/index.ts index 87cb5dd73..dee23fc93 100644 --- a/libs/walletd-js/src/index.ts +++ b/libs/walletd-js/src/index.ts @@ -47,6 +47,12 @@ import { WalletBalanceParams, WalletBalancePayload, WalletBalanceResponse, + WalletConstructV1TransactionParams, + WalletConstructV1TransactionPayload, + WalletConstructV1TransactionResponse, + WalletConstructV2TransactionParams, + WalletConstructV2TransactionPayload, + WalletConstructV2TransactionResponse, WalletDeleteParams, WalletDeletePayload, WalletDeleteResponse, @@ -93,6 +99,8 @@ import { walletsIdAddressesAddrRoute, walletsIdAddressesRoute, walletsIdBalanceRoute, + walletsIdConstructTransactionRoute, + walletsIdConstructV2TransactionRoute, walletsIdEventsRoute, walletsIdEventsUnconfirmedRoute, walletsIdFundRoute, @@ -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), } } diff --git a/libs/walletd-react/src/api.ts b/libs/walletd-react/src/api.ts index e81660ce4..8a43cad0a 100644 --- a/libs/walletd-react/src/api.ts +++ b/libs/walletd-react/src/api.ts @@ -51,6 +51,12 @@ import { WalletAddressesResponse, WalletBalanceParams, WalletBalanceResponse, + WalletConstructV1TransactionParams, + WalletConstructV1TransactionPayload, + WalletConstructV1TransactionResponse, + WalletConstructV2TransactionParams, + WalletConstructV2TransactionPayload, + WalletConstructV2TransactionResponse, WalletDeleteParams, WalletDeletePayload, WalletDeleteResponse, @@ -92,6 +98,8 @@ import { walletsIdAddressesAddrRoute, walletsIdAddressesRoute, walletsIdBalanceRoute, + walletsIdConstructTransactionRoute, + walletsIdConstructV2TransactionRoute, walletsIdEventsRoute, walletsIdEventsUnconfirmedRoute, walletsIdFundRoute, @@ -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 }) +} diff --git a/libs/walletd-types/src/api.ts b/libs/walletd-types/src/api.ts index 6dc9eaac0..58b11d139 100644 --- a/libs/walletd-types/src/api.ts +++ b/libs/walletd-types/src/api.ts @@ -11,6 +11,10 @@ import { Transaction, V2Transaction, WalletEvent, + SiacoinOutput, + Address, + SiafundOutput, + TransactionID, } from '@siafoundation/types' import { GatewayPeer, Wallet, WalletAddress, WalletMetadata } from './types' @@ -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 @@ -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[] } @@ -89,6 +98,7 @@ export type TxPoolFeeResponse = Currency export type TxPoolBroadcastParams = void export type TxPoolBroadcastPayload = { + basis: ChainIndex transactions: Transaction[] v2transactions: V2Transaction[] } @@ -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 +}