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

BDK wallet integration #110

Merged
merged 48 commits into from
Feb 1, 2024
Merged
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
0c14162
chore: update gitignore to exclude Cargo files
evanlinjin Jan 9, 2024
681fd7e
bdkwallet: initial work on BDK wallet
evanlinjin Jan 9, 2024
b6c8493
main: enfore rust toolchain version
evanlinjin Jan 25, 2024
bf84ba8
bdkwallet: workaround for golang uniffi bug
evanlinjin Jan 25, 2024
e6462ab
main: add install cmd to rust build script
evanlinjin Jan 25, 2024
4d9198f
main: Add signet folder to .gitignore
evanlinjin Jan 26, 2024
c641c3f
bdkwallet: apply mempool, list txs & utxos
evanlinjin Jan 26, 2024
69e9dfb
bdkwallet: add docs for wallet.go
evanlinjin Jan 27, 2024
d5efac7
bdkwallet: improve logging
evanlinjin Jan 27, 2024
30f41ca
main,bdkwallet: implement safe startup logic for BDK wallet
evanlinjin Jan 27, 2024
74a1ee4
bdkwallet: implement conditional building
evanlinjin Jan 29, 2024
aeb2485
bdkwallet: fix confirmations logic + docs
evanlinjin Jan 29, 2024
a5f0b10
main: add Makefile
evanlinjin Jan 29, 2024
5e90099
main: don't run linter on generated files
kcalvinalvin Jan 29, 2024
675027c
bdkwallet: export Wallet and add comments
kcalvinalvin Jan 30, 2024
4e6fc6f
main: clarify that we do handle wallet commands, just not btcwallet
kcalvinalvin Jan 30, 2024
ccfca83
main: add bdkwallet to the rpcserver
kcalvinalvin Jan 30, 2024
8ae10ac
btcjson: add support for unusedaddress command
kcalvinalvin Jan 30, 2024
6fea917
btcjson: add bdkaddressresult
kcalvinalvin Jan 30, 2024
4c8dad1
main: add unusedaddress support to rpcserver
kcalvinalvin Jan 30, 2024
0f7709b
btcjson: add support for freshaddress command
kcalvinalvin Jan 30, 2024
b8852fb
main: add freshaddress support to rpcserver
kcalvinalvin Jan 30, 2024
caccd7d
btcjson: add peekaddress command
kcalvinalvin Jan 30, 2024
6bbf5dc
main: add peekaddress command support to rpcserver
kcalvinalvin Jan 30, 2024
9d2b740
btcjson: add support for balance command
kcalvinalvin Jan 30, 2024
545bba0
main: add balance command support to the rpcserver
kcalvinalvin Jan 30, 2024
1662863
main: add bdkwallet tag on the tests
kcalvinalvin Jan 30, 2024
d99cdcb
btcjson: add support for createtransactionfrombdkwallet command
kcalvinalvin Jan 30, 2024
140dd4b
btcjson: add support for createtransactionfrombdkwalletresult
kcalvinalvin Jan 31, 2024
9256bb1
main: add createtransactionfrombdkwallet support to rpcserver
kcalvinalvin Jan 30, 2024
e5711d6
bdkwallet: pass in human-readable address to rust
evanlinjin Jan 30, 2024
ffd9a72
btcjson: add getmnemonicwords command
kcalvinalvin Jan 31, 2024
69f00b6
main: add getmnemonicwords command to rpcserver
kcalvinalvin Jan 31, 2024
48a5385
btcjson: add listbdktransactions command
kcalvinalvin Jan 31, 2024
46788c9
btcjson: add support for listbdktransactions result
kcalvinalvin Jan 31, 2024
18369f1
main: add support for listbdktransactions command in rpcserver
kcalvinalvin Jan 31, 2024
65f5618
main: notify bdkwallet and watchonly wallet for rpcserver
kcalvinalvin Jan 31, 2024
c2836bd
bdkwallet: general fixup
kcalvinalvin Jan 31, 2024
964d572
main: fix Makefile
evanlinjin Jan 31, 2024
9398196
bdkwallet: update BDK
evanlinjin Jan 31, 2024
66df88b
btcjson: add support for rebroadcastunconfirmedbdktxs
kcalvinalvin Jan 31, 2024
848b261
main: add support for rebroadcastunconfirmedbdktxs command
kcalvinalvin Jan 31, 2024
ba14596
main: change handleCreateTransactionFromBDKWallet to send txs to
kcalvinalvin Feb 1, 2024
23ec5ad
btcjson: add support for listbdkutxos
kcalvinalvin Feb 1, 2024
779ca92
main: add listbdkutxos support to rpc
kcalvinalvin Feb 1, 2024
3a96310
bdkwallet: reverse hashes
kcalvinalvin Feb 1, 2024
5103c9e
main: enable bdkwallet if the wallet exists
kcalvinalvin Feb 1, 2024
8bdc980
main: make bdk wallet enabled by default
kcalvinalvin Feb 1, 2024
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
Prev Previous commit
Next Next commit
bdkwallet: general fixup
Just generally making the code idiomatic.
kcalvinalvin committed Feb 1, 2024
commit c2836bd54e667d88ec1d879621b98e0085857ce7
28 changes: 17 additions & 11 deletions bdkwallet/bdkwallet.go
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import "C"

import (
"bytes"
"encoding/hex"

"github.com/utreexo/utreexod/bdkwallet/bdkgo"
"github.com/utreexo/utreexod/btcutil"
@@ -144,10 +145,9 @@ func (w *BDKWallet) ApplyBlock(block *btcutil.Block) error {
if err != nil {
return err
}
bhash := block.Hash()
for _, genTxid := range res.RelevantTxids {
txid := hashFromBytes(genTxid)
log.Infof("Found relevant tx %v in block %v:%v.", txid, bheight, bhash)
for _, txid := range res.RelevantTxids {
log.Infof("Found relevant tx %v in block %v:%v.",
hex.EncodeToString(txid), bheight, block.Hash().String())
}
return nil
}
@@ -160,7 +160,7 @@ func (w *BDKWallet) ApplyMempoolTransactions(txns []*mempool.TxDesc) error {
genTxns := make([]bdkgo.MempoolTx, 0, len(txns))
for _, tx := range txns {
var txb bytes.Buffer
if err := tx.Tx.MsgTx().BtcEncode(&txb, wire.FeeFilterVersion, wire.WitnessEncoding); err != nil {
if err := tx.Tx.MsgTx().BtcEncode(&txb, 0, wire.WitnessEncoding); err != nil {
return err
}
genTxns = append(genTxns, bdkgo.MempoolTx{
@@ -172,9 +172,8 @@ func (w *BDKWallet) ApplyMempoolTransactions(txns []*mempool.TxDesc) error {
if err != nil {
return err
}
for _, genTxid := range res.RelevantTxids {
txid := *(*[32]byte)(genTxid)
log.Infof("Found relevant tx %v in mempool.", txid)
for _, txid := range res.RelevantTxids {
log.Infof("Found relevant tx %v in mempool.", hex.EncodeToString(txid))
}
return nil
}
@@ -197,19 +196,26 @@ func (w *BDKWallet) MnemonicWords() []string {
}

// Transactions returns the list of wallet transactions.
func (w *BDKWallet) Transactions() []TxInfo {
func (w *BDKWallet) Transactions() ([]TxInfo, error) {
genOut := w.inner.Transactions()
out := make([]TxInfo, 0, len(genOut))

for _, info := range genOut {
tx, err := btcutil.NewTxFromBytes(info.Tx)
if err != nil {
return nil, err
}

out = append(out, TxInfo{
Txid: hashFromBytes(info.Txid),
Tx: txFromBytes(info.Tx),
Tx: *tx,
Spent: btcutil.Amount(info.Spent),
Received: btcutil.Amount(info.Received),
Confirmations: uint(info.Confirmations),
})
}
return out

return out, nil
}

// Utxos returns the list of wallet UTXOs.
12 changes: 1 addition & 11 deletions bdkwallet/wallet.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package bdkwallet

import (
"bytes"
"errors"

"github.com/utreexo/utreexod/btcutil"
"github.com/utreexo/utreexod/chaincfg"
"github.com/utreexo/utreexod/chaincfg/chainhash"
"github.com/utreexo/utreexod/mempool"
"github.com/utreexo/utreexod/wire"
)

var (
@@ -45,7 +43,7 @@ type Wallet interface {
ApplyMempoolTransactions(txns []*mempool.TxDesc) error
CreateTx(feerate float32, recipients []Recipient) ([]byte, error)
MnemonicWords() []string
Transactions() []TxInfo
Transactions() ([]TxInfo, error)
UTXOs() []UTXOInfo
}

@@ -103,14 +101,6 @@ func hashFromBytes(b []byte) chainhash.Hash {
return *(*[32]byte)(b)
}

func txFromBytes(b []byte) btcutil.Tx {
var msgTx wire.MsgTx
if err := msgTx.BtcDecode(bytes.NewReader(b), wire.FeeFilterVersion, wire.WitnessEncoding); err != nil {
panic("must decode tx consensus bytes from rust")
}
return *btcutil.NewTx(&msgTx)
}

func uintPointerFromUint32Pointer(v *uint32) *uint {
if v == nil {
return nil