rpcserver+lnd_test: adding check in SendCoins to prevent txs sent to pubkeys

This commit is contained in:
ccdle12
2019-04-10 10:45:55 +08:00
parent ab4a6750cc
commit c46457fb5b
2 changed files with 40 additions and 1 deletions

View File

@@ -913,6 +913,15 @@ func (r *rpcServer) SendCoins(ctx context.Context,
activeNetParams.Params.Name)
}
// If the destination address parses to a valid pubkey, we assume the user
// accidently tried to send funds to a bare pubkey address. This check is
// here to prevent unintended transfers.
decodedAddr, _ := hex.DecodeString(in.Addr)
_, err = btcec.ParsePubKey(decodedAddr, btcec.S256())
if err == nil {
return nil, fmt.Errorf("cannot send coins to pubkeys")
}
var txid *chainhash.Hash
wallet := r.server.cc.wallet