walletrpc: add LabelTransaction rpc

This commit is contained in:
carla committed 2020-05-25 11:33:33 +02:00
1 parent baeef63aab
commit 97a843f3cd
6 files changed
+361 -90

No files matched your search

+33
View File
@@ -94,6 +94,10 @@ var (
Entity: "onchain",
Action: "read",
}},
"/walletrpc.WalletKit/LabelTransaction": {{
Entity: "onchain",
Action: "write",
}},
}
// DefaultWalletKitMacFilename is the default name of the wallet kit
@@ -102,6 +106,10 @@ var (
DefaultWalletKitMacFilename = "walletkit.macaroon"
)
// ErrZeroLabel is returned when an attempt is made to label a transaction with
// an empty label.
var ErrZeroLabel = errors.New("cannot label transaction with empty label")
// WalletKit is a sub-RPC server that exposes a tool kit which allows clients
// to execute common wallet operations. This includes requesting new addresses,
// keys (for contracts!), and publishing transactions.
@@ -635,3 +643,28 @@ func (w *WalletKit) ListSweeps(ctx context.Context,
},
}, nil
}
// LabelTransaction adds a label to a transaction.
func (w *WalletKit) LabelTransaction(ctx context.Context,
req *LabelTransactionRequest) (*LabelTransactionResponse, error) {
// Check that the label provided in non-zero.
if len(req.Label) == 0 {
return nil, ErrZeroLabel
}
// Validate the length of the non-zero label. We do not need to use the
// label returned here, because the original is non-zero so will not
// be replaced.
if _, err := labels.ValidateAPI(req.Label); err != nil {
return nil, err
}
hash, err := chainhash.NewHash(req.Txid)
if err != nil {
return nil, err
}
err = w.cfg.Wallet.LabelTransaction(*hash, req.Label, req.Overwrite)
return &LabelTransactionResponse{}, err
}