private: Distinguish between privateFor being absent vs. an empty array to allow self-sending (#165)

This commit is contained in:
Patrick Mylund Nielsen 2017-09-01 08:54:00 -04:00 committed by Joel Burget
parent a218568402
commit ece3a79607
2 changed files with 5 additions and 18 deletions

View File

@ -359,7 +359,7 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs
}
data := []byte(args.Data)
isPrivate := len(args.PrivateFor) > 0
isPrivate := args.PrivateFor != nil
if isPrivate {
log.Info("sending private tx", "data", fmt.Sprintf("%x", data), "privatefrom", args.PrivateFrom, "privatefor", args.PrivateFor)
data, err = private.P.Send(data, args.PrivateFrom, args.PrivateFor)
@ -1137,7 +1137,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
}
data := []byte(args.Data)
isPrivate := len(args.PrivateFor) > 0
isPrivate := args.PrivateFor != nil
if isPrivate {
log.Info("sending private tx", "data", fmt.Sprintf("%x", data), "privatefrom", args.PrivateFrom, "privatefor", args.PrivateFor)

View File

@ -6,28 +6,15 @@ import (
"time"
)
func copyBytes(b []byte) []byte {
ob := make([]byte, len(b))
copy(ob, b)
return ob
}
type Constellation struct {
node *Client
c *cache.Cache
}
func (g *Constellation) Send(data []byte, from string, to []string) (out []byte, err error) {
if len(data) > 0 {
if len(to) == 0 {
out = copyBytes(data)
} else {
var err error
out, err = g.node.SendPayload(data, from, to)
if err != nil {
return nil, err
}
}
out, err = g.node.SendPayload(data, from, to)
if err != nil {
return nil, err
}
g.c.Set(string(out), data, cache.DefaultExpiration)
return out, nil