Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

txnbuild: enables multiple signatures #1198

Merged
merged 7 commits into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions txnbuild/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func newKeypair(seed string) *keypair.Full {
return myKeypair.(*keypair.Full)
}

func buildSignEncode(tx Transaction, kp *keypair.Full, t *testing.T) (txeBase64 string) {
func buildSignEncode(t *testing.T, tx Transaction, kps ...*keypair.Full) (txeBase64 string) {
var err error
debnil marked this conversation as resolved.
Show resolved Hide resolved
err = tx.Build()
assert.NoError(t, err)

err = tx.Sign(kp)
err = tx.Sign(kps...)
assert.NoError(t, err)

txeBase64, err = tx.Base64()
Expand Down
10 changes: 5 additions & 5 deletions txnbuild/payment.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (
// Payment represents the Stellar payment operation. See
// https://www.stellar.org/developers/guides/concepts/list-of-operations.html
type Payment struct {
Destination string
Amount string
Asset Asset
Destination string
Amount string
Asset Asset
SourceAccount *xdr.AccountId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, I think this would be better as an Account type, as is down with the same field in Transaction.

  1. It matches Transaction.SourceAccount
  2. Caller can pass an account directly after retrieving it from horizonclient
  3. Caller doesn't have to fiddle with the xdr construction, which is kind of awkward as it's a setter

}

// BuildXDR for Payment returns a fully configured XDR Operation.
Expand Down Expand Up @@ -43,6 +44,5 @@ func (p *Payment) BuildXDR() (xdr.Operation, error) {
Asset: xdrAsset,
}
body, err := xdr.NewOperationBody(opType, xdrOp)

return xdr.Operation{Body: body}, errors.Wrap(err, "failed to build XDR OperationBody")
return xdr.Operation{SourceAccount: p.SourceAccount, Body: body}, errors.Wrap(err, "failed to build XDR OperationBody")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do we set the new field p.SourceAccount?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nvm. It looks like we expect the caller to set it

}
20 changes: 10 additions & 10 deletions txnbuild/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (tx *Transaction) Build() error {

// Sign for Transaction signs a previously built transaction. A signed transaction may be
// submitted to the network.
func (tx *Transaction) Sign(kp *keypair.Full) error {
func (tx *Transaction) Sign(kps ...*keypair.Full) error {
// TODO: Only sign if Transaction has been previously built
// TODO: Validate network set before sign
// Initialise transaction envelope
Expand All @@ -142,27 +142,27 @@ func (tx *Transaction) Sign(kp *keypair.Full) error {
}

// Sign the hash
// TODO: Allow multiple signers
sig, err := kp.SignDecorated(hash[:])
if err != nil {
return errors.Wrap(err, "failed to sign transaction")
for _, kp := range kps {
sig, err := kp.SignDecorated(hash[:])
if err != nil {
return errors.Wrap(err, "failed to sign transaction")
}
// Append the signature to the envelope
tx.xdrEnvelope.Signatures = append(tx.xdrEnvelope.Signatures, sig)
}

// Append the signature to the envelope
tx.xdrEnvelope.Signatures = append(tx.xdrEnvelope.Signatures, sig)

return nil
}

// BuildSignEncode performs all the steps to produce a final transaction suitable
// for submitting to the network.
func (tx *Transaction) BuildSignEncode(keypair *keypair.Full) (string, error) {
func (tx *Transaction) BuildSignEncode(keypairs ...*keypair.Full) (string, error) {
err := tx.Build()
if err != nil {
return "", errors.Wrap(err, "couldn't build transaction")
}

err = tx.Sign(keypair)
err = tx.Sign(keypairs...)
if err != nil {
return "", errors.Wrap(err, "couldn't sign transaction")
}
Expand Down
Loading