OSDN Git Service

add is_reverse modify_politic_list_transactions
authormars <mars@bytom.io>
Mon, 16 Dec 2019 03:09:38 +0000 (11:09 +0800)
committermars <mars@bytom.io>
Mon, 16 Dec 2019 03:09:38 +0000 (11:09 +0800)
api/query.go
blockchain/pseudohsm/pseudohsm.go
wallet/indexer.go
wallet/wallet_test.go

index 7015522..e72e574 100644 (file)
@@ -135,6 +135,7 @@ func (a *API) listTransactions(ctx context.Context, filter struct {
        Detail       bool   `json:"detail"`
        Unconfirmed  bool   `json:"unconfirmed"`
        Count        uint   `json:"count"`
+       IsReverse    bool   `json:"is_reverse"`
 }) Response {
        accountID := filter.AccountID
        if filter.AccountAlias != "" {
@@ -145,7 +146,7 @@ func (a *API) listTransactions(ctx context.Context, filter struct {
                accountID = acc.ID
        }
 
-       transactions, err := a.wallet.GetTransactions(accountID, filter.StartTxID, filter.Count, filter.Unconfirmed)
+       transactions, err := a.wallet.GetTransactions(accountID, filter.StartTxID, filter.Count, filter.Unconfirmed, filter.IsReverse)
        if err != nil {
                return NewErrorResponse(err)
        }
index 5c13844..42f18d5 100644 (file)
@@ -125,6 +125,24 @@ func (h *HSM) createKeyFromMnemonic(alias string, auth string, mnemonic string)
        return &XPub{XPub: xpub, Alias: alias, File: file}, nil
 }
 
+func (h *HSM) CreateKey(xprv chainkd.XPrv, alias string, auth string) (*XPub, error) {
+       xpub := xprv.XPub()
+       id := uuid.NewRandom()
+       key := &XKey{
+               ID:      id,
+               KeyType: "bytom_kd",
+               XPub:    xpub,
+               XPrv:    xprv,
+               Alias:   alias,
+       }
+
+       file := h.keyStore.JoinPath(keyFileName(key.ID.String()))
+       if err := h.keyStore.StoreKey(file, key, auth); err != nil {
+               return nil, errors.Wrap(err, "storing keys")
+       }
+       return &XPub{XPub: xpub, Alias: alias, File: file}, nil
+}
+
 func (h *HSM) createChainKDKey(alias string, auth string, language string) (*XPub, *string, error) {
        // Generate a mnemonic for memorization or user-friendly seeds
        entropy, err := mnem.NewEntropy(EntropyLength)
index 9cf3392..4294a54 100644 (file)
@@ -239,7 +239,7 @@ func findTransactionsByAccount(annotatedTx *query.AnnotatedTx, accountID string)
 }
 
 // GetTransactions get all walletDB transactions or unconfirmed transactions, and filter transactions by accountID and StartTxID optional
-func (w *Wallet) GetTransactions(accountID string, StartTxID string, count uint, unconfirmed bool) ([]*query.AnnotatedTx, error) {
+func (w *Wallet) GetTransactions(accountID string, StartTxID string, count uint, unconfirmed bool, isReverse bool) ([]*query.AnnotatedTx, error) {
        annotatedTxs := []*query.AnnotatedTx{}
        var startKey []byte
        preFix := TxPrefix
@@ -260,7 +260,7 @@ func (w *Wallet) GetTransactions(accountID string, StartTxID string, count uint,
                preFix = UnconfirmedTxPrefix
        }
 
-       itr := w.DB.IteratorPrefixWithStart([]byte(preFix), startKey, true)
+       itr := w.DB.IteratorPrefixWithStart([]byte(preFix), startKey, isReverse)
        defer itr.Release()
 
        for txNum := count; itr.Next() && txNum > 0; {
index b65a65c..d8272b8 100644 (file)
@@ -161,7 +161,7 @@ func TestWalletUpdate(t *testing.T) {
                t.Fatal(err)
        }
 
-       wants, err := w.GetTransactions("", "", 100, false)
+       wants, err := w.GetTransactions("", "", 100, false, true)
        if len(wants) != 1 {
                t.Fatal(err)
        }