1 package wallet
2 3 import (
4 "github.com/p9c/p9/pkg/chainhash"
5 "github.com/p9c/p9/pkg/walletdb"
6 "github.com/p9c/p9/pkg/wtxmgr"
7 )
8 9 // UnstableAPI exposes unstable api in the wallet
10 type UnstableAPI struct {
11 w *Wallet
12 }
13 14 // ExposeUnstableAPI exposes additional unstable public APIs for a Wallet. These APIs may be changed or removed at any
15 // time. Currently this type exists to ease the transation (particularly for the legacy JSON-RPC server) from using
16 // exported manager packages to a unified wallet package that exposes all functionality by itself. New code should not
17 // be written using this API.
18 func ExposeUnstableAPI(w *Wallet) UnstableAPI {
19 return UnstableAPI{w}
20 }
21 22 // TxDetails calls wtxmgr.Store.TxDetails under a single database view transaction.
23 func (u UnstableAPI) TxDetails(txHash *chainhash.Hash) (details *wtxmgr.TxDetails, e error) {
24 e = walletdb.View(
25 u.w.db, func(dbtx walletdb.ReadTx) (e error) {
26 txmgrNs := dbtx.ReadBucket(wtxmgrNamespaceKey)
27 details, e = u.w.TxStore.TxDetails(txmgrNs, txHash)
28 return e
29 },
30 )
31 return
32 }
33 34 // RangeTransactions calls wtxmgr.Store.RangeTransactions under a single database view transaction.
35 func (u UnstableAPI) RangeTransactions(begin, end int32, f func([]wtxmgr.TxDetails) (bool, error)) error {
36 return walletdb.View(
37 u.w.db, func(dbtx walletdb.ReadTx) (e error) {
38 txmgrNs := dbtx.ReadBucket(wtxmgrNamespaceKey)
39 return u.w.TxStore.RangeTransactions(txmgrNs, begin, end, f)
40 },
41 )
42 }
43