Skip to content

Commit

Permalink
zec: Satisfy WalletHistorian.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins committed Jun 17, 2024
1 parent 8830fbb commit 6eb0e91
Show file tree
Hide file tree
Showing 3 changed files with 832 additions and 7 deletions.
56 changes: 54 additions & 2 deletions client/asset/zec/transparent_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,29 @@ func lockUnspent(c rpcCaller, unlock bool, ops []*btc.Output) error {
return err
}

func getTransaction(c rpcCaller, txHash *chainhash.Hash) (*dexzec.Tx, error) {
type zTx struct {
*dexzec.Tx
blockHash *chainhash.Hash
}

func getTransaction(c rpcCaller, txHash *chainhash.Hash) (*zTx, error) {
var tx btc.GetTransactionResult
if err := c.CallRPC("gettransaction", []any{txHash.String()}, &tx); err != nil {
return nil, err
}
return dexzec.DeserializeTx(tx.Bytes)
dexzecTx, err := dexzec.DeserializeTx(tx.Bytes)
if err != nil {
return nil, err
}
blockHash, err := chainhash.NewHashFromStr(tx.BlockHash)
if err != nil {
return nil, fmt.Errorf("invalid block hash for transaction: %v", err)
}
zt := &zTx{
Tx: dexzecTx,
blockHash: blockHash,
}
return zt, nil
}

func getRawTransaction(c rpcCaller, txHash *chainhash.Hash) ([]byte, error) {
Expand Down Expand Up @@ -347,3 +364,38 @@ func syncStatus(c rpcCaller) (*btc.SyncStatus, error) {
Syncing: chainInfo.Syncing(),
}, nil
}

type listSinceBlockRes struct {
Transactions []btcjson.ListTransactionsResult `json:"transactions"`
}

func listSinceBlock(c rpcCaller, txHash *chainhash.Hash) ([]btcjson.ListTransactionsResult, error) {
var res listSinceBlockRes
if err := c.CallRPC("listsinceblock", []any{txHash.String()}, &res); err != nil {
return nil, err
}
return res.Transactions, nil
}

type walletInfoRes struct {
WalletVersion int `json:"walletversion"`
Balance float64 `json:"balance"`
UnconfirmedBalance float64 `json:"unconfirmed_balance"`
ImmatureBalance float64 `json:"immature_balance"`
ShieldedBalance string `json:"shielded_balance"`
ShieldedUnconfirmedBalance string `json:"shielded_unconfirmed_balance"`
TxCount int `json:"txcount"`
KeypoolOldest int `json:"keypoololdest"`
KeypoolSize int `json:"keypoolsize"`
PayTxFee float64 `json:"paytxfee"`
MnemonicSeedfp string `json:"mnemonic_seedfp"`
LegacySeedfp string `json:"legacy_seedfp,omitempty"`
}

func walletInfo(c rpcCaller) (*walletInfoRes, error) {
var res walletInfoRes
if err := c.CallRPC("getwalletinfo", nil, &res); err != nil {
return nil, err
}
return &res, nil
}
Loading

0 comments on commit 6eb0e91

Please sign in to comment.