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: provide simple account implementation #1266

Closed
2 tasks
ire-and-curses opened this issue May 10, 2019 · 1 comment
Closed
2 tasks

txnbuild: provide simple account implementation #1266

ire-and-curses opened this issue May 10, 2019 · 1 comment
Labels
txnbuild 2nd-generation transaction build library for Go SDK

Comments

@ire-and-curses
Copy link
Member

ire-and-curses commented May 10, 2019

The interface txnbuild.Account defines the requirements for an account used by transactions and operations. Often, the workflow is to obtain an account using horizonclient, and then use this to build new transactions.

However, this is not always the case. It would be helpful to provide a minimal implementation SimpleAccount for situations where an account is not coming from a horizonclient call. This functionality is needed in friendbot, and the bridge server, for example. It would also simplify txnbuild test code, which currently has this funky helper method:

func makeTestAccount(kp *keypair.Full, seqnum string) hProtocol.Account {
	return hProtocol.Account{
		HistoryAccount: hProtocol.HistoryAccount{
			AccountID: kp.Address(),
		},
		Sequence: seqnum,
	}
}

@debnil has a minimal implementation here. We could move something like this to txnbuild. Also see the implementation in protocols/horizon:

// GetSequenceNumber returns the sequence number of the account,
// and returns it as a 64-bit integer.
func (a Account) GetSequenceNumber() (xdr.SequenceNumber, error) {
	seqNum, err := strconv.ParseUint(a.Sequence, 10, 64)

	if err != nil {
		return 0, errors.Wrap(err, "Failed to parse account sequence number")
	}

	return xdr.SequenceNumber(seqNum), nil
}

// IncrementSequenceNumber increments the internal record of the account's sequence
// number by 1. This is typically used after a transaction build so that the next
// transaction to be built will be valid.
func (a *Account) IncrementSequenceNumber() (xdr.SequenceNumber, error) {
	seqNum, err := a.GetSequenceNumber()
	if err != nil {
		return xdr.SequenceNumber(0), err
	}
	seqNum++
	a.Sequence = strconv.FormatInt(int64(seqNum), 10)
	return a.GetSequenceNumber()
}
  • Implement minimal account struct matching Account interface
  • Switch tests over to new account
@ire-and-curses ire-and-curses added the txnbuild 2nd-generation transaction build library for Go SDK label May 10, 2019
@ire-and-curses ire-and-curses added this to the txnbuild v1.2.0 milestone May 13, 2019
@ire-and-curses
Copy link
Member Author

Closed by #1271

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
txnbuild 2nd-generation transaction build library for Go SDK
Projects
None yet
Development

No branches or pull requests

1 participant