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 GitHub
parent 5dfdecef4c
commit 9faa0ed123
2 changed files with 6 additions and 19 deletions

View File

@ -277,7 +277,7 @@ func (s *PrivateAccountAPI) SendTransaction(ctx context.Context, args SendTxArgs
var tx *types.Transaction
data := common.FromHex(args.Data)
isPrivate := len(args.PrivateFor) > 0
isPrivate := args.PrivateFor != nil
if isPrivate {
data, err = private.P.Send(data, args.PrivateFrom, args.PrivateFor)
if err != nil {
@ -377,7 +377,7 @@ func (a *Async) save(ctx context.Context, s *PublicTransactionPoolAPI, args Send
if err != nil {
return common.Hash{}, err
}
return submitTransaction(ctx, s.b, tx, signature, len(args.PrivateFor) > 0)
return submitTransaction(ctx, s.b, tx, signature, args.PrivateFor != nil)
}
func newAsync(n int) *Async {
@ -1202,7 +1202,7 @@ func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args Sen
var tx *types.Transaction
data := common.FromHex(args.Data)
isPrivate := len(args.PrivateFor) > 0
isPrivate := args.PrivateFor != nil
if isPrivate {
data, err = private.P.Send(data, args.PrivateFrom, args.PrivateFor)
if err != nil {

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