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

Account name #155

Merged
merged 1 commit into from
Mar 19, 2015
Merged

Account name #155

merged 1 commit into from
Mar 19, 2015

Conversation

tuxcanfly
Copy link
Contributor

NOTE: This pull request requires #147

Updated waddrmgr to support account names and integrated with wallet RPC calls.

@davecgh
Copy link
Member

davecgh commented Dec 17, 2014

Thanks @tuxcanfly. I'll go through and review this as time permits. It's obviously a huge change.

// The returned value is a slice of account numbers which can be used to load
// the respective account rows.
func fetchAllAccounts(tx walletdb.Tx) ([]uint32, error) {
accounts := []uint32{}
Copy link
Member

Choose a reason for hiding this comment

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

Please add a TODO here to load the number of accounts from the db first and create the slice with enough space for them all at once. Otherwise, it's hard on the GC because it has to grow the backing array multiple times.

Also, super nit picky, but every other function has the bucket := ... line as the first one in the function, so I'd prefer that be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm now using a 'meta' bucket to store metadata like no of accounts, no of addrs etc and using it to create sized slices.

Moved bucket := ... to the first line.

@davecgh
Copy link
Member

davecgh commented Dec 31, 2014

I'm still reviewing, but one thing in general I want to bring up that we should discuss is how to avoid loading all of the addresses into a slice at once. That will not scale to millions/billions of addresses.

@@ -1657,6 +1861,19 @@ func checkBranchKeys(acctKey *hdkeychain.ExtendedKey) error {
return err
}

// ValidateAccountName validates the given account name and returns an error, if any.
func ValidateAccountName(name string) error {
Copy link
Member

Choose a reason for hiding this comment

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

I know that Go doesn't really care where the functions are placed, but the rest of code base strives to define functions before they are used. Please move this before NewAccount which is the first (and only) thing that uses it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@tuxcanfly tuxcanfly force-pushed the account-name branch 10 times, most recently from 7da37c9 to 5d7176a Compare January 7, 2015 09:17
@@ -862,14 +1225,108 @@ func existsAddress(tx walletdb.Tx, addressID []byte) bool {
return bucket.Get(addrHash[:]) != nil
}

// fetchAddrAccount returns the account to which the given address belongs to.
// It looks up the account using the addracctidx index which maps the address
// hash to it's corresponding account id.
Copy link
Member

Choose a reason for hiding this comment

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

it's -> its

@@ -38,6 +39,8 @@ var (
latestMgrVersion uint32 = LatestMgrVersion
)

type obtainFunc func() ([]byte, error)
Copy link
Member

Choose a reason for hiding this comment

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

This should be exported since it's used in the Confg struct. It'll need a comment too once exported.

@tuxcanfly tuxcanfly force-pushed the account-name branch 4 times, most recently from 4c34e2d to fbd7aea Compare March 17, 2015 15:15
@jrick
Copy link
Member

jrick commented Mar 17, 2015

I think that the account names should not be set in the RPC handlers for gettransaction and listtransactions. These fields are deprecated in recent bitcoind wallet versions (which makes sense, since account balances there can change without an on-chain transaction) and we have plans for a proper ledger RPC to report credits and debits across accounts that is intentionally incompatible with bitcoind.

@tuxcanfly
Copy link
Contributor Author

@jrick Agreed, that would simplify some hoops I had to jump through to make the RPC results compat with core.

"github.com/btcsuite/btcwallet/chain"
"github.com/btcsuite/btcwallet/txstore"
"github.com/btcsuite/btcwallet/waddrmgr"
"github.com/btcsuite/btcwallet/walletdb"
"golang.org/x/crypto/ssh/terminal"
Copy link
Member

Choose a reason for hiding this comment

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

Use "github.com/btcsuite/golangcrypto/ssh/terminal".

}

err := checkAccountName(account)
err := checkAccountName(*cmd.Account)
Copy link
Member

Choose a reason for hiding this comment

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

This is not safe. The field is optional and this may be nil.

@tuxcanfly
Copy link
Contributor Author

@jrick Thanks, updated.

@davecgh
Copy link
Member

davecgh commented Mar 18, 2015

Alright, this looks good to go! Please squash it down to a single commit and rebase to the latest master.

@tuxcanfly
Copy link
Contributor Author

Done.

@conformal-deploy conformal-deploy merged commit 68a9168 into btcsuite:master Mar 19, 2015
@tuxcanfly
Copy link
Contributor Author

Great! Thanks for the patient reviews @davecgh @jrick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants