From db5d692c426703ea809914fed9a2370c25d7f2d6 Mon Sep 17 00:00:00 2001 From: Alex Freska Date: Thu, 7 Dec 2023 16:00:47 -0500 Subject: [PATCH] refactor: types --- apps/hostd/contexts/config/transform.spec.ts | 4 +- apps/hostd/contexts/config/transform.ts | 4 +- apps/hostd/contexts/transactions/index.tsx | 41 +-- apps/hostd/contexts/volumes/dataset.ts | 3 +- apps/hostd/contexts/volumes/types.ts | 1 - .../dialogs/HostdTransactionDetailsDialog.tsx | 33 +-- apps/hostd/dialogs/VolumeDeleteDialog.tsx | 2 +- apps/renterd/contexts/transactions/index.tsx | 4 +- .../src/app/TransactionDetailsDialog.tsx | 68 +++-- libs/react-core/src/siaTypes.ts | 191 ++++++------ libs/react-hostd/src/api.ts | 8 +- libs/react-hostd/src/siaTypes.ts | 7 +- libs/react-renterd/src/autopilot.ts | 11 +- libs/react-renterd/src/bus.ts | 102 ++++++- libs/react-renterd/src/siaTypes.ts | 274 ++++-------------- libs/react-walletd/src/api.ts | 14 +- libs/react-walletd/src/siaTypes.ts | 122 +------- 17 files changed, 356 insertions(+), 533 deletions(-) diff --git a/apps/hostd/contexts/config/transform.spec.ts b/apps/hostd/contexts/config/transform.spec.ts index 820b4c4c2..297c50990 100644 --- a/apps/hostd/contexts/config/transform.spec.ts +++ b/apps/hostd/contexts/config/transform.spec.ts @@ -27,7 +27,7 @@ describe('data transforms', () => { ipv4: false, ipv6: false, options: { - ID: 'ID', + id: 'ID', secret: 'secret', zoneID: 'zone', }, @@ -128,7 +128,7 @@ describe('data transforms', () => { ipv4: false, ipv6: false, options: { - ID: 'ID', + id: 'ID', secret: 'secret', zoneID: 'zone', }, diff --git a/apps/hostd/contexts/config/transform.ts b/apps/hostd/contexts/config/transform.ts index fece51fa4..45df7932e 100644 --- a/apps/hostd/contexts/config/transform.ts +++ b/apps/hostd/contexts/config/transform.ts @@ -45,7 +45,7 @@ export function transformUp( // DNS AWS if (values.dnsProvider === 'route53') { dnsOptions = { - ID: values.dnsAwsId, + id: values.dnsAwsId, secret: values.dnsAwsSecret, zoneID: values.dnsAwsZoneId, } as DNSAWSOptions @@ -144,7 +144,7 @@ export function transformDown(s: HostSettings): SettingsData { // DNS AWS if (s.ddns.provider === 'route53') { dnsOptions = { - dnsAwsId: s.ddns.options['ID'], + dnsAwsId: s.ddns.options['id'], dnsAwsSecret: s.ddns.options['secret'], dnsAwsZoneId: s.ddns.options['zoneID'], } diff --git a/apps/hostd/contexts/transactions/index.tsx b/apps/hostd/contexts/transactions/index.tsx index c09cb4276..9bd4b9e91 100644 --- a/apps/hostd/contexts/transactions/index.tsx +++ b/apps/hostd/contexts/transactions/index.tsx @@ -15,29 +15,26 @@ import { useDialog } from '../dialog' import BigNumber from 'bignumber.js' import { useRouter } from 'next/router' import { useSiascanUrl } from '../../hooks/useSiascanUrl' +import { Transaction } from '@siafoundation/react-core' const defaultLimit = 50 const filters = [] -export type TransactionDataPending = { - type: 'transaction' - txType: TxType - siascanUrl: string -} - -export type TransactionDataConfirmed = { +export type TransactionData = { + id: string type: 'transaction' txType: TxType hash: string + inflow: string + outflow: string timestamp: number onClick: () => void - unconfirmed: boolean + unconfirmed?: boolean sc: BigNumber siascanUrl: string + raw: Transaction } -export type TransactionData = TransactionDataPending | TransactionDataConfirmed - function useTransactionsMain() { const router = useRouter() const limit = Number(router.query.limit || defaultLimit) @@ -72,29 +69,39 @@ function useTransactionsMain() { ...(pending.data || []).map((t): TransactionData => { const notRealTxn = t.source !== 'transaction' return { + id: t.id, type: 'transaction', + unconfirmed: true, txType: getTransactionType(t.transaction, t.source), - hash: t.ID, - timestamp: new Date(t.timestamp).getTime(), + hash: t.id, + inflow: t.inflow, + outflow: t.outflow, sc: new BigNumber(t.inflow).minus(t.outflow), - unconfirmed: true, siascanUrl: notRealTxn ? undefined : siascanUrl, + timestamp: new Date(t.timestamp).getTime(), + onClick: () => openDialog('transactionDetails', t.id), + raw: t.transaction, } }), ...(transactions.data || []) .map((t): TransactionData => { const notRealTxn = t.source !== 'transaction' return { + id: t.id, type: 'transaction', + unconfirmed: false, txType: getTransactionType(t.transaction, t.source), - hash: t.ID, - timestamp: new Date(t.timestamp).getTime(), - onClick: () => openDialog('transactionDetails', t.ID), + hash: t.id, + inflow: t.inflow, + outflow: t.outflow, sc: new BigNumber(t.inflow).minus(t.outflow), siascanUrl: notRealTxn ? undefined : siascanUrl, + timestamp: new Date(t.timestamp).getTime(), + onClick: () => openDialog('transactionDetails', t.id), + raw: t.transaction, } }) - .sort((a, b) => (a['timestamp'] < b['timestamp'] ? 1 : -1)), + .sort((a, b) => (a.timestamp < b.timestamp ? 1 : -1)), ] }, [pending, transactions, openDialog, siascanUrl]) diff --git a/apps/hostd/contexts/volumes/dataset.ts b/apps/hostd/contexts/volumes/dataset.ts index 745e67cd9..e17498420 100644 --- a/apps/hostd/contexts/volumes/dataset.ts +++ b/apps/hostd/contexts/volumes/dataset.ts @@ -23,8 +23,7 @@ export function useDataset({ function getFields(c: VolumeMeta): VolumeData { return { - id: String(c.ID), - ID: c.ID, + id: String(c.id), localPath: c.localPath, usedSectors: c.usedSectors, usedBytes: new BigNumber(c.usedSectors).times(MiBToBytes(4)).toNumber(), diff --git a/apps/hostd/contexts/volumes/types.ts b/apps/hostd/contexts/volumes/types.ts index 465fa6c40..e45e981fe 100644 --- a/apps/hostd/contexts/volumes/types.ts +++ b/apps/hostd/contexts/volumes/types.ts @@ -3,7 +3,6 @@ import BigNumber from 'bignumber.js' export type VolumeData = { id: string - ID: number localPath: string usedSectors: number totalSectors: number diff --git a/apps/hostd/dialogs/HostdTransactionDetailsDialog.tsx b/apps/hostd/dialogs/HostdTransactionDetailsDialog.tsx index 4529638b3..e820f7fc3 100644 --- a/apps/hostd/dialogs/HostdTransactionDetailsDialog.tsx +++ b/apps/hostd/dialogs/HostdTransactionDetailsDialog.tsx @@ -1,38 +1,15 @@ import { useMemo } from 'react' -import { - getTransactionType, - TransactionDetailsDialog, -} from '@siafoundation/design-system' -import { useWalletTransactions } from '@siafoundation/react-hostd' +import { TransactionDetailsDialog } from '@siafoundation/design-system' import { useDialog } from '../contexts/dialog' +import { useTransactions } from '../contexts/transactions' export function HostdTransactionDetailsDialog() { const { id, dialog, openDialog, closeDialog } = useDialog() + const { dataset } = useTransactions() - // TODO: add transaction endpoint - const transactions = useWalletTransactions({ - params: {}, - config: { - swr: { - revalidateOnFocus: false, - refreshInterval: 60_000, - }, - }, - disabled: dialog !== 'transactionDetails', - }) const transaction = useMemo(() => { - const txn = transactions.data?.find((t) => t.ID === id) - if (!txn) { - return null - } - return { - txType: getTransactionType(txn.transaction, txn.source), - inflow: txn.inflow, - outflow: txn.outflow, - timestamp: txn.timestamp, - raw: txn.transaction, - } - }, [transactions, id]) + return dataset?.find((t) => t.id === id) + }, [dataset, id]) return ( { const response = await volumeDelete.delete({ params: { - id: volume.data?.ID, + id: volume.data?.id, force: values.force, }, }) diff --git a/apps/renterd/contexts/transactions/index.tsx b/apps/renterd/contexts/transactions/index.tsx index 64612ad01..5a8ab54df 100644 --- a/apps/renterd/contexts/transactions/index.tsx +++ b/apps/renterd/contexts/transactions/index.tsx @@ -81,9 +81,9 @@ function useTransactionsMain() { return { type: 'transaction', txType: getTransactionType(t), - // hash: t.ID, + // hash: t.id, // timestamp: new Date(t.Timestamp).getTime(), - // onClick: () => openDialog('transactionDetails', t.ID), + // onClick: () => openDialog('transactionDetails', t.id), // sc: totals.sc, unconfirmed: true, siascanUrl, diff --git a/libs/design-system/src/app/TransactionDetailsDialog.tsx b/libs/design-system/src/app/TransactionDetailsDialog.tsx index 3efe28e7b..0427ed7fe 100644 --- a/libs/design-system/src/app/TransactionDetailsDialog.tsx +++ b/libs/design-system/src/app/TransactionDetailsDialog.tsx @@ -13,10 +13,10 @@ type Props = { id: string transaction?: { txType: TxType - inflow: string - outflow: string - timestamp: string | number - raw: Transaction + inflow?: string + outflow?: string + timestamp?: string | number + raw?: Transaction } trigger?: React.ReactNode open: boolean @@ -49,36 +49,44 @@ export function TransactionDetailsDialog({ {transaction ? (
-
- Inflow - -
-
- Outflow - -
-
- Miner fee - acc.plus(val), - new BigNumber(0) - ) || 0 - ) - } - /> -
+ {transaction?.inflow !== undefined && ( +
+ Inflow + +
+ )} + {transaction?.outflow !== undefined && ( +
+ Outflow + +
+ )} + {transaction?.raw?.minerFees !== undefined && ( +
+ Miner fee + acc.plus(val), + new BigNumber(0) + ) || 0 + ) + } + /> +
+ )}
Timestamp - {humanDate(transaction?.timestamp || 0, { - timeStyle: 'short', - })} + {transaction?.timestamp + ? humanDate(transaction?.timestamp || 0, { + timeStyle: 'short', + }) + : 'Unconfirmed'}
diff --git a/libs/react-core/src/siaTypes.ts b/libs/react-core/src/siaTypes.ts index e4770692b..044b79b13 100644 --- a/libs/react-core/src/siaTypes.ts +++ b/libs/react-core/src/siaTypes.ts @@ -2,60 +2,50 @@ export type ID = string export type Hash256 = string export type Signature = string export type Currency = string +export type BlockHeight = number export type Hash = string export type OutputID = string export type EncryptionKey = string export type FileContractID = string export type PublicKey = string export type TransactionID = string +export type SiacoinOutputID = Hash256 +export type SiafundOutputID = Hash256 +export type Address = string -export interface SiaPublicKey { - Algorithm: string - Key?: string -} - -export interface UnlockConditions { - Timelock: number - PublicKeys?: SiaPublicKey[] - SignaturesRequired: number -} - -export interface FileContractRevision { - ParentID: string - UnlockConditions: UnlockConditions - RevisionNumber: number - Filesize: number - FileMerkleRoot: string - WindowStart: number - WindowEnd: number - ValidProofOutputs?: SiacoinOutput[] - MissedProofOutputs?: SiacoinOutput[] - UnlockHash: string -} - -export interface CoveredFields { - WholeTransaction: boolean - SiacoinInputs?: number[] - SiacoinOutputs?: number[] - FileContracts?: number[] - FileContractRevisions?: number[] - StorageProofs?: number[] - SiafundInputs?: number[] - SiafundOutputs?: number[] - MinerFees?: number[] - ArbitraryData?: number[] - Signatures?: number[] -} - -export interface TransactionSignature { - ParentID: string - PublicKeyIndex: number - Timelock: number - CoveredFields: CoveredFields - Signature?: string -} - -export interface SiacoinInput { +export type SiaPublicKey = { + algorithm: string + key?: string +} + +export type UnlockConditions = { + timelock: number + publicKeys?: SiaPublicKey[] + signaturesRequired: number +} + +export type FileContractRevision = { + parentID: string + unlockConditions: UnlockConditions + revisionNumber: number + filesize: number + fileMerkleRoot: string + windowStart: number + windowEnd: number + validProofOutputs?: SiacoinOutput[] + missedProofOutputs?: SiacoinOutput[] + unlockHash: string +} + +export type TransactionSignature = { + parentID: string + publicKeyIndex: number + timelock: number + coveredFields: CoveredFields + signature?: string +} + +export type SiacoinInput = { parentID: string unlockConditions: UnlockConditions } @@ -65,36 +55,78 @@ export type SiacoinOutput = { address: string } -export interface FileContract { - Filesize: number - FileMerkleRoot: string - WindowStart: number - WindowEnd: number - Payout: Currency - ValidProofOutputs?: SiacoinOutput[] - MissedProofOutputs?: SiacoinOutput[] - UnlockHash: string - RevisionNumber: number +export type SiacoinElement = { + id: string + leafIndex: number + merkleProof: string[] | null + siacoinOutput: SiacoinOutput + maturityHeight: number } -export interface StorageProof { - ParentID: string - Segment: string - Hashset?: Hash[] +export type SiafundElement = { + id: string + leafIndex: number + merkleProof: string[] | null + siafundOutput: SiafundOutput + claimStart: string } -export interface SiafundInput { +export type SiafundElementAndClaim = { + siafundElement: SiafundElement + claimElement: SiacoinElement +} + +export type CoveredFields = { + wholeTransaction: boolean + siacoinInputs?: number[] + siacoinOutputs?: number[] + fileContracts?: number[] + fileContractRevisions?: number[] + storageProofs?: number[] + siafundInputs?: number[] + siafundOutputs?: number[] + minerFees?: number[] + arbitraryData?: number[] + signatures?: number[] +} + +export type FileContractElement = { + id: string + leafIndex: number + merkleProof: string[] | null + fileContract: FileContract +} + +export type FileContract = { + filesize: number + fileMerkleRoot: string + windowStart: number + windowEnd: number + payout: Currency + validProofOutputs?: SiacoinOutput[] + missedProofOutputs?: SiacoinOutput[] + unlockHash: string + revisionNumber: number +} + +export type StorageProof = { + parentID: string + segment: string + hashset?: Hash[] +} + +export type SiafundInput = { parentID: string unlockConditions: UnlockConditions - claimUnlockHash: string + claimAddress: string } -export interface SiafundOutput { +export type SiafundOutput = { value: number address: string } -export interface Transaction { +export type Transaction = { siacoinInputs?: SiacoinInput[] siacoinOutputs?: SiacoinOutput[] fileContracts?: FileContract[] @@ -107,26 +139,15 @@ export interface Transaction { transactionSignatures?: TransactionSignature[] } -export interface Block { - ParentID: string - Nonce: string - Timestamp: number - MinerPayouts?: SiacoinOutput[] - Transactions?: Transaction[] -} - -export interface ChainIndex { - Height: number - ID: string -} - -export interface SiaPublicKey { - Algorithm: string - Key?: string +export type Block = { + parentID: string + nonce: string + timestamp: number + minerPayouts?: SiacoinOutput[] + transactions?: Transaction[] } -export interface UnlockConditions { - Timelock: number - PublicKeys?: SiaPublicKey[] - SignaturesRequired: number +export type ChainIndex = { + height: number + id: string } diff --git a/libs/react-hostd/src/api.ts b/libs/react-hostd/src/api.ts index 66c00b5e6..0271e9801 100644 --- a/libs/react-hostd/src/api.ts +++ b/libs/react-hostd/src/api.ts @@ -28,7 +28,7 @@ export type StateHost = { network: 'Mainnet' | 'Zen Testnet' version: string commit: string - OS: string + os: string buildTime: string } @@ -44,7 +44,7 @@ export function useStateHost(args?: HookArgsSwr) { export type StateConsensus = { chainIndex: { height: number - ID: string + id: string } synced: boolean } @@ -358,7 +358,7 @@ export type DNSNoIPOptions = { // AWS export type DNSAWSOptions = { - ID: string + id: string secret: string zoneID: string } @@ -456,7 +456,7 @@ export function useSettingsDdns( // volumes export type Volume = { - ID: number + id: number localPath: string usedSectors: number totalSectors: number diff --git a/libs/react-hostd/src/siaTypes.ts b/libs/react-hostd/src/siaTypes.ts index 9a74bc607..13a08cfcb 100644 --- a/libs/react-hostd/src/siaTypes.ts +++ b/libs/react-hostd/src/siaTypes.ts @@ -9,8 +9,11 @@ import { } from '@siafoundation/react-core' export interface WalletTransaction { - ID: string - index: string // ChainIndex + id: string + index: { + id: string + height: number + } inflow: Currency outflow: Currency source: string diff --git a/libs/react-renterd/src/autopilot.ts b/libs/react-renterd/src/autopilot.ts index 08d97a140..1b97b0ed9 100644 --- a/libs/react-renterd/src/autopilot.ts +++ b/libs/react-renterd/src/autopilot.ts @@ -1,4 +1,4 @@ -import { Action, AutopilotConfig, Host } from './siaTypes' +import { AutopilotConfig, Host } from './siaTypes' import { HostsSearchPayload, StateResponse } from './bus' import { useGetSwr, @@ -55,15 +55,6 @@ export function useAutopilotConfigUpdate( }) } -export function useAutopilotActions( - args?: HookArgsSwr<{ since?: number; max?: number }, Action[]> -) { - return useGetSwr({ - ...args, - route: '/autopilot/actions', - }) -} - export type AutopilotHost = { host: Host checks?: { diff --git a/libs/react-renterd/src/bus.ts b/libs/react-renterd/src/bus.ts index 9e7aa18db..63e270a73 100644 --- a/libs/react-renterd/src/bus.ts +++ b/libs/react-renterd/src/bus.ts @@ -14,27 +14,20 @@ import { getMainnetBlockHeight, getTestnetZenBlockHeight, delay, + FileContractRevision, + OutputID, + CoveredFields, + FileContractID, + Block, } from '@siafoundation/react-core' import { - AddObjectRequest, - Block, ConsensusState, Contract, - ContractAcquireRequest, - ContractAcquireResponse, - ContractsIDAddRequest, - ContractsIDRenewedRequest, + ContractRevision, Host, - Interaction, + HostSettings, Obj, SiacoinElement, - WalletFundRequest, - WalletFundResponse, - WalletPrepareFormRequest, - WalletPrepareRenewRequest, - WalletPrepareRenewResponse, - WalletRedistributeRequest, - WalletSignRequest, WalletTransaction, } from './siaTypes' @@ -196,18 +189,40 @@ export function useWalletUtxos(args?: HookArgsSwr) { return useGetSwr({ ...args, route: '/bus/wallet/outputs' }) } +export type WalletFundRequest = { + transaction: Transaction + amount: Currency +} + +export type WalletFundResponse = { + transaction: Transaction + toSign?: OutputID[] + dependsOn?: Transaction[] +} + export function useWalletFund( args?: HookArgsCallback ) { return usePostFunc({ ...args, route: '/bus/wallet/fund' }) } +export type WalletSignRequest = { + transaction: Transaction + toSign?: OutputID[] + coveredFields: CoveredFields +} + export function useWalletSign( args?: HookArgsCallback ) { return usePostFunc({ ...args, route: '/bus/wallet/sign' }) } +export type WalletRedistributeRequest = { + amount: Currency + outputs: number +} + export function useWalletRedistribute( args?: HookArgsCallback ) { @@ -220,12 +235,37 @@ export function useWalletDiscard( return usePostFunc({ ...args, route: '/bus/wallet/discard' }) } +export type WalletPrepareFormRequest = { + renterKey?: string + hostKey: string + renterFunds: Currency + renterAddress: string + hostCollateral: Currency + endHeight: number + hostSettings: HostSettings +} + export function useWalletPrepareForm( args?: HookArgsCallback ) { return usePostFunc({ ...args, route: '/bus/wallet/prepare/form' }) } +export type WalletPrepareRenewRequest = { + contract: FileContractRevision + renterKey?: string + hostKey: string + renterFunds: Currency + renterAddress: string + endHeight: number + hostSettings: HostSettings +} + +export type WalletPrepareRenewResponse = { + transactionSet?: Transaction[] + finalPayment: Currency +} + export function useWalletPrepareRenew( args?: HookArgsCallback< void, @@ -292,8 +332,14 @@ export function useHost(args: HookArgsSwr<{ hostKey: string }, Host>) { return useGetSwr({ ...args, route: '/bus/host/:hostKey' }) } +export type HostInteractionPayload = { + timestamp: string + type: string + result?: string +} + export function useHostsPubkeyInteractionAdd( - args: HookArgsCallback<{ hostKey: string }, Interaction, never> + args: HookArgsCallback<{ hostKey: string }, HostInteractionPayload, never> ) { return usePostFunc({ ...args, @@ -367,6 +413,14 @@ export function useContracts(args?: HookArgsSwr) { return useGetSwr({ ...args, route: contractsActiveRoute }) } +export type ContractAcquireRequest = { + Duration: number +} + +export type ContractAcquireResponse = { + locked: boolean +} + export function useContractsAcquire( args: HookArgsCallback< { id: string }, @@ -387,12 +441,25 @@ export function useContract(args: HookArgsSwr<{ id: string }, Contract>) { return useGetSwr({ ...args, route: '/bus/contract/:id' }) } +export type ContractsIDAddRequest = { + contract: ContractRevision + startHeight: number + totalCost: Currency +} + export function useContractCreate( args: HookArgsCallback<{ id: string }, ContractsIDAddRequest, Contract> ) { return usePostFunc({ ...args, route: '/bus/contract/:id/new' }) } +export type ContractsIDRenewedRequest = { + contract: ContractRevision + renewedFrom: string + startHeight: number + totalCost: Currency +} + export function useContractRenew( args: HookArgsCallback<{ id: string }, ContractsIDRenewedRequest, Contract> ) { @@ -513,6 +580,11 @@ export function useObjectSearch( return useGetSwr({ ...args, route: '/bus/search/objects' }) } +export type AddObjectRequest = { + object: Obj + usedContracts: { [key: PublicKey]: FileContractID } +} + export function useObjectAdd( args: HookArgsCallback< { key: string; bucket: string }, diff --git a/libs/react-renterd/src/siaTypes.ts b/libs/react-renterd/src/siaTypes.ts index 8407598b0..809383255 100644 --- a/libs/react-renterd/src/siaTypes.ts +++ b/libs/react-renterd/src/siaTypes.ts @@ -1,79 +1,25 @@ import { ChainIndex, - CoveredFields, FileContractRevision, - SiacoinOutput, Transaction, Currency, - OutputID, EncryptionKey, - FileContractID, PublicKey, + TransactionSignature, } from '@siafoundation/react-core' -export interface ConsensusState { +export type ConsensusState = { blockHeight: number synced: boolean lastBlockTime: string } -export interface ContractAcquireRequest { - Duration: number +export type ContractRevision = { + revision: FileContractRevision + signatures: TransactionSignature[] } -export interface TransactionSignature { - ParentID: string - PublicKeyIndex: number - Timelock: number - CoveredFields: CoveredFields - Signature?: string -} - -export interface ContractRevision { - Revision: FileContractRevision - Signatures: TransactionSignature[] -} - -export interface ContractsIDAddRequest { - contract: ContractRevision - startHeight: number - totalCost: Currency -} - -export interface ContractsIDRenewedRequest { - contract: ContractRevision - renewedFrom: string - startHeight: number - totalCost: Currency -} - -export interface ContractAcquireResponse { - locked: boolean -} - -export interface WalletFundRequest { - transaction: Transaction - amount: Currency -} - -export interface WalletFundResponse { - transaction: Transaction - toSign?: OutputID[] - dependsOn?: Transaction[] -} - -export interface WalletSignRequest { - transaction: Transaction - toSign?: OutputID[] - coveredFields: CoveredFields -} - -export interface WalletRedistributeRequest { - amount: Currency - outputs: number -} - -export interface HostSettings { +export type HostSettings = { acceptingcontracts: boolean maxdownloadbatchsize: number maxduration: number @@ -99,49 +45,51 @@ export interface HostSettings { siamuxport: string } -export interface WalletPrepareFormRequest { - renterKey?: string - hostKey: string - renterFunds: Currency - renterAddress: string - hostCollateral: Currency - endHeight: number - hostSettings: HostSettings -} - -export interface WalletPrepareRenewRequest { - contract: FileContractRevision - renterKey?: string - hostKey: string - renterFunds: Currency - renterAddress: string - endHeight: number - hostSettings: HostSettings -} - -export interface WalletPrepareRenewResponse { - transactionSet?: Transaction[] - finalPayment: Currency +export type HostPriceTable = { + acceptingcontracts: boolean + baserpcprice: string + collateral: string + contractprice: string + downloadbandwidthprice: string + ephemeralaccountexpiry: number + maxcollateral: string + maxdownloadbatchsize: number + maxduration: number + maxephemeralaccountbalance: string + maxrevisebatchsize: number + netaddress: string + remainingstorage: number + revisionnumber: number + sectoraccessprice: string + sectorsize: number + siamuxport: string + storageprice: string + totalstorage: number + unlockhash: string + uploadbandwidthprice: string + version: string + windowsize: number } -export interface Sector { +export type Sector = { host: string root: string } -export interface Slab { + +export type Slab = { health: number key: EncryptionKey minShards: number shards: Sector[] } -export interface SlabSlice { +export type SlabSlice = { slab: Slab offset: number length: number } -export interface Obj { +export type Obj = { name: string size: number health: number @@ -154,28 +102,6 @@ export interface Obj { } } -export interface AddObjectRequest { - object: Obj - usedContracts: { [key: PublicKey]: FileContractID } -} - -export interface DownloadParams { - ContractSet: string -} - -export interface UploadParams { - CurrentHeight: number - MinShards: number - TotalShards: number - ContractSet: string -} - -export interface MigrateParams { - CurrentHeight: number - FromContracts: string - ToContracts: string -} - export type ContractSetSettings = { default: string } @@ -203,7 +129,7 @@ export type RedundancySettings = { totalShards: number } -export interface ContractSpending { +export type ContractSpending = { uploads: Currency downloads: Currency fundAccount: Currency @@ -211,7 +137,7 @@ export interface ContractSpending { export type ContractState = 'pending' | 'active' | 'complete' | 'failed' -export interface Contract { +export type Contract = { id: string hostIP: string hostKey: string @@ -228,126 +154,48 @@ export interface Contract { state: ContractState } -export interface Block { - parentid: string - nonce: string - timestamp: number - minerpayouts?: SiacoinOutput[] - transactions?: Transaction[] +export type HostInteractions = { + downtime: number + failedInteractions: number + lastScan?: string + lastScanSuccess: boolean + lostSectors: number + secondToLastScanSuccess: boolean + successfulInteractions: number + totalScans: number + uptime: number } -export interface Interaction { - Timestamp: string - Type: string - Result?: string -} - -export interface Host { +export type Host = { publicKey: string netAddress: string knownSince: string lastAnnouncement: string - interactions: { - downtime: number - failedInteractions: number - lastScan?: string - lastScanSuccess: boolean - lostSectors: number - secondToLastScanSuccess: boolean - successfulInteractions: number - totalScans: number - uptime: number - } + interactions: HostInteractions scanned: boolean - priceTable?: { - accountbalancecost: string - collateralcost: string - contractprice: string - downloadbandwidthcost: string - dropsectorsbasecost: string - dropsectorsunitcost: string - expiry: string // date - fundaccountcost: string - hassectorbasecost: string - hostblockheight: number - initbasecost: string - latestrevisioncost: string - maxcollateral: string - maxduration: number - memorytimecost: string - readbasecost: string - readlengthcost: string - registryentriesleft: number - registryentriestotal: number - renewcontractcost: string - revisionbasecost: string - subscriptionmemorycost: string - subscriptionnotificationcost: string - swapsectorcost: string - txnfeemaxrecommended: string - txnfeeminrecommended: string - uid: string - updatepricetablecost: string - uploadbandwidthcost: string - validity: number - windowsize: number - writebasecost: string - writelengthcost: string - writestorecost: string - } - settings?: { - acceptingcontracts: boolean - baserpcprice: string - collateral: string - contractprice: string - downloadbandwidthprice: string - ephemeralaccountexpiry: number - maxcollateral: string - maxdownloadbatchsize: number - maxduration: number - maxephemeralaccountbalance: string - maxrevisebatchsize: number - netaddress: string - remainingstorage: number - revisionnumber: number - sectoraccessprice: string - sectorsize: number - siamuxport: string - storageprice: string - totalstorage: number - unlockhash: string - uploadbandwidthprice: string - version: string - windowsize: number - } + priceTable?: HostPriceTable + settings?: HostSettings } -export interface SiacoinElement { - Value: Currency - Address: string - ID: string - MaturityHeight: number -} - -export interface Action { - Timestamp: string - Type: string - // eslint-disable-next-line @typescript-eslint/no-explicit-any - Action: any +export type SiacoinElement = { + value: Currency + address: string + id: string + maturityHeight: number } -export interface AutopilotWalletConfig { +export type AutopilotWalletConfig = { defragThreshold: number } -export interface AutopilotHostsConfig { +export type AutopilotHostsConfig = { allowRedundantIPs: boolean scoreOverrides: { [key: PublicKey]: number } maxDowntimeHours: number minRecentScanFailures: number } -export interface AutopilotContractsConfig { +export type AutopilotContractsConfig = { set: string amount: number allowance: Currency @@ -359,13 +207,13 @@ export interface AutopilotContractsConfig { prune: boolean } -export interface AutopilotConfig { +export type AutopilotConfig = { wallet: AutopilotWalletConfig hosts: AutopilotHostsConfig contracts: AutopilotContractsConfig } -export interface WalletTransaction { +export type WalletTransaction = { raw: Transaction index: ChainIndex id: string diff --git a/libs/react-walletd/src/api.ts b/libs/react-walletd/src/api.ts index 460178148..09322c973 100644 --- a/libs/react-walletd/src/api.ts +++ b/libs/react-walletd/src/api.ts @@ -10,18 +10,18 @@ import { getTestnetZenBlockHeight, useDeleteFunc, Currency, -} from '@siafoundation/react-core' -import { BlockHeight, ChainIndex, - ConsensusState, - ConsensusNetwork, - PoolTransaction, - SiacoinElement, SiacoinOutputID, - SiafundElement, SiafundOutputID, + SiacoinElement, + SiafundElement, Transaction, +} from '@siafoundation/react-core' +import { + ConsensusState, + ConsensusNetwork, + PoolTransaction, WalletEvent, GatewayPeer, } from './siaTypes' diff --git a/libs/react-walletd/src/siaTypes.ts b/libs/react-walletd/src/siaTypes.ts index 7b3e6637f..7fd0c1a3d 100644 --- a/libs/react-walletd/src/siaTypes.ts +++ b/libs/react-walletd/src/siaTypes.ts @@ -1,16 +1,13 @@ -import { Currency, Hash256 } from '@siafoundation/react-core' - -export type BlockHeight = number -export type SiacoinOutputID = Hash256 -export type SiafundOutputID = Hash256 -export type Address = string - -// TODO: synchronize with other daemons and react-core - -export type ChainIndex = { - height: number - ID: string -} +import { + Currency, + ChainIndex, + Transaction, + Address, + SiacoinElement, + SiafundElementAndClaim, + SiafundElement, + FileContractElement, +} from '@siafoundation/react-core' export type ConsensusNetwork = { name: 'mainnet' | 'zen' @@ -80,105 +77,6 @@ export type GatewayPeer = { syncDuration: number } -export type UnlockConditions = { - timelock: number - publicKeys?: string[] - signaturesRequired: number -} - -export type SiacoinInput = { - parentID: string - unlockConditions: UnlockConditions -} - -export type SiacoinOutput = { - value: string - address: string -} - -export type SiafundInput = { - parentID: string - unlockConditions: UnlockConditions - claimAddress: string -} - -export type SiafundOutput = { - value: number - address: string -} - -export type SiacoinElement = { - id: string - leafIndex: number - merkleProof: string[] | null - siacoinOutput: SiacoinOutput - maturityHeight: number -} - -export type SiafundElement = { - id: string - leafIndex: number - merkleProof: string[] | null - siafundOutput: SiafundOutput - claimStart: string -} - -export type SiafundElementAndClaim = { - siafundElement: SiafundElement - claimElement: SiacoinElement -} - -export type TransactionSignature = { - parentID: string - publicKeyIndex: number - timelock: number - coveredFields: CoveredFields - signature?: string -} - -export type CoveredFields = { - wholeTransaction: boolean - siacoinInputs?: number[] - siacoinOutputs?: number[] - fileContracts?: number[] - fileContractRevisions?: number[] - storageProofs?: number[] - siafundInputs?: number[] - siafundOutputs?: number[] - minerFees?: number[] - arbitraryData?: number[] - signatures?: number[] -} - -export interface Transaction { - siacoinInputs?: SiacoinInput[] - siacoinOutputs?: SiacoinOutput[] - siafundInputs?: SiafundInput[] - siafundOutputs?: SiafundOutput[] - minerFees?: Currency[] - arbitraryData?: string[] - signatures?: TransactionSignature[] -} - -export type FileContract = { - filesize: number - fileMerkleRoot: string - windowStart: number - windowEnd: number - payout: string - validProofOutputs: SiacoinOutput[] - missedProofOutputs: SiacoinOutput[] - unlockHash: string - revisionNumber: number -} - -export type FileContractElement = { - id: string - leafIndex: number - merkleProof: string[] | null - fileContract: FileContract -} - export type PoolTransaction = { id: string raw: Transaction