-
Notifications
You must be signed in to change notification settings - Fork 606
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
Account name #155
Conversation
Thanks @tuxcanfly. I'll go through and review this as time permits. It's obviously a huge change. |
0722d9c
to
a12fd58
Compare
a12fd58
to
53ea9c5
Compare
// 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{} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
7da37c9
to
5d7176a
Compare
@@ -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. |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
4c34e2d
to
fbd7aea
Compare
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. |
@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" |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
@jrick Thanks, updated. |
Alright, this looks good to go! Please squash it down to a single commit and rebase to the latest master. |
Done. |
NOTE: This pull request requires #147
Updated
waddrmgr
to support account names and integrated with wallet RPC calls.