-
Notifications
You must be signed in to change notification settings - Fork 36
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
[#1511] Refactor account representation from int to a dedicated account structure #1515
base: 1514-Finish-multi-account-support
Are you sure you want to change the base?
Conversation
… to a dedicated Account structure - First iteration of all Int account references to an instance of an Account
- The ID of account is now public co clients can read-only it
- Zip32 accounts represented with Int32 are now refactored to Zip32Account - from_account_id/fto_account_id are now refactored to AccountId
// | ||
|
||
/// A [ZIP 32](https://zips.z.cash/zip-0032) account index. | ||
public struct Zip32Account: Equatable, Codable, Hashable { |
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 a much needed change!
|
||
/// A [ZIP 32](https://zips.z.cash/zip-0032) account index. | ||
public struct Zip32Account: Equatable, Codable, Hashable { | ||
public let index: Int32 |
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 would take the opportunity to make this UInt32 and internally then convert to Int32.
Also I the derivation tool in the FFI derives the Network Id as UInt32 when u32
is specified in Rust, so we could make that change later.
If the public API uses UInt32 then this change in Rust won't imply a deprecation in the SDK's public API. then the init can get rid of the fatalError()
call.
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.
The valid range is 0..<(1<<31)
(because the high bit is used in ZIP 32 / BIP 32 to indicate "hardened" which doesn't apply to account indices), so it doesn't really matter from that point of view whether it is stored as Int32
or UInt32
. That is, the fatalError
from init
would be needed regardless.
I've gone back and forth on this, but after careful consideration I agree that the public API should use UInt32
. There are not actually many places where we have to convert when calling zcashlc_*
functions that take an account parameter, and this PR is changing all of them anyway.
public let index: Int32 | |
public let index: UInt32 |
@@ -103,11 +103,13 @@ class SendViewController: UIViewController { | |||
} | |||
|
|||
func updateBalance() async { | |||
let account = Zip32Account(0) |
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.
Even though this is only sample code, I'd suggest making this an attribute of SendViewController
so that it's only hardcoded once. (There's no need to do anything more than that.)
} | ||
} | ||
|
||
public struct AccountId: Equatable, Codable, Hashable { |
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 would prefer this to be called LocalAccountId
. (See also zcash/librustzcash#1631 (comment) .)
public struct AccountId: Equatable, Codable, Hashable { | |
public struct LocalAccountId: Equatable, Codable, Hashable { |
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.
No, this will become the account ID containing the UUID; the local one will not be visible to the Swift code.
} | ||
|
||
public struct AccountId: Equatable, Codable, Hashable { | ||
public let index: Int |
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.
public let index: Int | |
public let id: Int |
public init(_ index: Int) { | ||
guard index >= 0 else { | ||
fatalError("Account index must be >= 0. Input value is \(index).") | ||
} | ||
|
||
self.index = index | ||
} |
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.
public init(_ index: Int) { | |
guard index >= 0 else { | |
fatalError("Account index must be >= 0. Input value is \(index).") | |
} | |
self.index = index | |
} | |
/// - Parameter id: the local account id, which must be nonnegative. | |
public init(_ id: Int) { | |
guard id >= 0 else { | |
fatalError("Local account id must be >= 0. Input value is \(id).") | |
} | |
self.id = id | |
} |
@@ -22,7 +22,8 @@ extension SaplingParamsAction: Action { | |||
|
|||
func run(with context: ActionContext, didUpdate: @escaping (CompactBlockProcessor.Event) async -> Void) async throws -> ActionContext { | |||
logger.debug("Fetching sapling parameters") | |||
try await saplingParametersHandler.handleIfNeeded() | |||
// TODO: This is hardcoded Zip32Account for index 0, must be updated |
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 file an issue like the lint says.
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.
We already have one: #1512
@@ -11,9 +11,9 @@ protocol SentNoteEntity { | |||
var id: Int { get } | |||
var transactionId: Int { get } | |||
var outputIndex: Int { get } | |||
var fromAccount: Int { get } | |||
var fromAccount: AccountId { get } |
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.
var fromAccount: AccountId { get } | |
var fromAccount: LocalAccountId { get } |
and every similar case.
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.
No, per my above comment (it would just get renamed back in the next PR).
/// - Parameter accountIndex:account that the key can spend from | ||
/// - Throws: `rustDeriveUnifiedSpendingKey` if rust layer returns error. | ||
func deriveUnifiedSpendingKey(from seed: [UInt8], accountIndex: Int32) throws -> UnifiedSpendingKey |
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.
/// - Parameter accountIndex:account that the key can spend from | |
/// - Throws: `rustDeriveUnifiedSpendingKey` if rust layer returns error. | |
func deriveUnifiedSpendingKey(from seed: [UInt8], accountIndex: Int32) throws -> UnifiedSpendingKey | |
/// - Parameter accountIndex: the ZIP 32 index of the account from which the key can spend | |
/// - Throws: `rustDeriveUnifiedSpendingKey` if rust layer returns error. | |
func deriveUnifiedSpendingKey(from seed: [UInt8], accountIndex: Zip32AccountIndex) throws -> UnifiedSpendingKey |
/// - Throws: | ||
/// - `derivationToolInvalidAccount` if the `accountIndex` is invalid. | ||
/// - `derivationToolInvalidAccount` if the `account.index` is invalid. |
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 think this error cannot occur here; please check.
/// - `derivationToolInvalidAccount` if the `account.index` is invalid. |
@@ -94,9 +93,9 @@ protocol ZcashKeyDerivationBackendWelding { | |||
/// | |||
/// - Parameter contextString: a globally-unique non-empty sequence of at most 252 bytes that identifies the desired context. | |||
/// - Parameter seed: `[Uint8]` seed bytes | |||
/// - Parameter accountNumber: `Int32` with the account number | |||
/// - Parameter accountIndex: `Int32` with the account number |
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.
/// - Parameter accountIndex: `Int32` with the account number | |
/// - Parameter accountIndex: the ZIP 32 index of the account |
/// - Throws: | ||
/// - `derivationToolInvalidAccount` if the `accountIndex` is invalid. | ||
/// - `derivationToolInvalidAccount` if the `account.index` is invalid. |
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.
Change accountIndex: Int32
to accountIndex: Zip32AccountIndex
below. Then, this exception cannot occur because the account index will have been checked to be in the valid range (which is all that is required here; it does not have to be an index of an account known to the wallet).
/// - `derivationToolInvalidAccount` if the `account.index` is invalid. |
public init(_ index: Int32) { | ||
guard index >= 0 else { | ||
fatalError("Account index must be >= 0. Input value is \(index).") | ||
} |
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.
public init(_ index: Int32) { | |
guard index >= 0 else { | |
fatalError("Account index must be >= 0. Input value is \(index).") | |
} | |
/// - Parameter index: the ZIP 32 account index, which must be less than ``1<<31``. | |
public init(_ index: UInt32) { | |
guard index < (1<<31) else { | |
fatalError("Account index must be less than 1<<31. Input value is \(index).") | |
} |
Note that many of my other suggestions depend on having made this change.
let ufvk: String | ||
} | ||
|
||
extension DbAccount: Hashable { | ||
func hash(into hasher: inout Hasher) { | ||
hasher.combine(account) | ||
hasher.combine(account.index) |
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.
Changing the type of index
to UInt32
causes no problem here.
|
||
for i in (0 ..< Int(accountsPtr.pointee.len)) { | ||
let account = accountsPtr.pointee.ptr.advanced(by: i).pointee | ||
accounts.append(Int32(account.account_index)) | ||
accounts.append(Zip32Account(Int32(account.account_index))) |
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.
accounts.append(Zip32Account(Int32(account.account_index))) | |
accounts.append(Zip32AccountIndex(account.account_index)) |
to address: String, | ||
value: Int64, | ||
memo: MemoBytes? | ||
) async throws -> FfiProposal { | ||
let proposal = zcashlc_propose_transfer( | ||
dbData.0, | ||
dbData.1, | ||
account, | ||
account.index, |
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.
Define typealias LCZip32Index = Int32
(local to this file), so that if we decide to change the type of account indices passed to zcashlc_*
functions, that can be done in one place (or at least we've marked all places that need to change).
account.index, | |
LCZip32Index(account.index), |
) async throws -> FfiProposal { | ||
let proposal = zcashlc_propose_transfer_from_uri( | ||
dbData.0, | ||
dbData.1, | ||
account, | ||
account.index, |
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.
account.index, | |
LCZip32Index(account.index), |
let addressCStr = zcashlc_get_current_address( | ||
dbData.0, | ||
dbData.1, | ||
account, | ||
account.index, |
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.
account.index, | |
LCZip32Index(account.index), |
let addressCStr = zcashlc_get_next_available_address( | ||
dbData.0, | ||
dbData.1, | ||
account, | ||
account.index, |
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.
account.index, | |
LCZip32Index(account.index), |
} | ||
|
||
let balance = zcashlc_get_total_transparent_balance_for_account( | ||
dbData.0, | ||
dbData.1, | ||
networkType.networkId, | ||
account | ||
account.index |
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.
account.index | |
LCZip32Index(account.index) |
} | ||
|
||
let balance = zcashlc_get_verified_transparent_balance_for_account( | ||
dbData.0, | ||
dbData.1, | ||
networkType.networkId, | ||
account, | ||
account.index, |
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.
account.index, | |
LCZip32Index(account.index), |
let encodedKeysPtr = zcashlc_list_transparent_receivers( | ||
dbData.0, | ||
dbData.1, | ||
account, | ||
account.index, |
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.
account.index, | |
LCZip32Index(account.index), |
memo: MemoBytes?, | ||
shieldingThreshold: Zatoshi, | ||
transparentReceiver: String? | ||
) async throws -> FfiProposal? { | ||
let proposal = zcashlc_propose_shielding( | ||
dbData.0, | ||
dbData.1, | ||
account, | ||
account.index, |
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.
account.index, | |
LCZip32Index(account.index), |
@@ -228,15 +228,15 @@ public protocol Synchronizer: AnyObject { | |||
memo: Memo? | |||
) async throws -> ZcashTransaction.Overview | |||
|
|||
/// Attempts to propose fulfilling a [ZIP-321](https://zips.z.cash/zip-0321) payment URI using the given `accountIndex` | |||
/// Attempts to propose fulfilling a [ZIP-321](https://zips.z.cash/zip-0321) payment URI using the given `account.index` |
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.
/// Attempts to propose fulfilling a [ZIP-321](https://zips.z.cash/zip-0321) payment URI using the given `account.index` | |
/// Attempts to propose fulfilling a [ZIP-321](https://zips.z.cash/zip-0321) payment URI by spending from the ZIP 32 account with the given index. |
|
||
/// Creates a proposal for transferring funds to the given recipient. | ||
/// | ||
/// - Parameter accountIndex: the account from which to transfer funds. | ||
/// - Parameter account: the account from which to transfer funds. |
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.
/// - Parameter account: the account from which to transfer funds. | |
/// - Parameter accountIndex: the ZIP 32 index of the account from which to transfer funds. |
and the same wording for every similar case.
/// - Parameter recipient: the recipient's address. | ||
/// - Parameter amount: the amount to send in Zatoshi. | ||
/// - Parameter memo: an optional memo to include as part of the proposal's transactions. Use `nil` when sending to transparent receivers otherwise the function will throw an error. | ||
/// | ||
/// If `prepare()` hasn't already been called since creation of the synchronizer instance or since the last wipe then this method throws | ||
/// `SynchronizerErrors.notPrepared`. | ||
func proposeTransfer( | ||
accountIndex: Int, | ||
account: Zip32Account, |
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.
account: Zip32Account, | |
accountIndex: Zip32AccountIndex, |
and every similar case.
|
||
/// Gets the unified address for the given account. | ||
/// - Parameter accountIndex: the optional accountId whose address is of interest. By default, the first account is used. | ||
/// - Parameter account: the account whose address is of interest. By default, the first account is used. |
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.
/// - Parameter account: the account whose address is of interest. By default, the first account is used. | |
/// - Parameter accountIndex: the ZIP 32 index of the account whose address is of interest. |
There is no default for this parameter.
|
||
/// Gets the transparent address for the given account. | ||
/// - Parameter accountIndex: the optional accountId whose address is of interest. By default, the first account is used. | ||
/// - Parameter account: the account whose address is of interest. By default, the first account is used. |
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.
/// - Parameter account: the account whose address is of interest. By default, the first account is used. | |
/// - Parameter accountIndex: the ZIP 32 index of the account whose address is of interest. |
There is no default for this parameter.
|
||
guard let tBalance = try await self.getAccountBalance(accountIndex: accountIndex)?.unshielded else { | ||
guard let tBalance = try await self.getAccountBalance(account: account)?.unshielded else { |
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.
Revert this.
@@ -394,9 +394,9 @@ public class SDKSynchronizer: Synchronizer { | |||
try throwIfUnprepared() | |||
|
|||
// let's see if there are funds to shield | |||
let accountIndex = Int(spendingKey.account) | |||
let account = Zip32Account(Int32(spendingKey.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.
let account = Zip32Account(Int32(spendingKey.account)) | |
let accountIndex = spendingKey.accountIndex |
(I am going to also suggest renaming UnifiedSpendingKey.index
and changing its type to Zip32AccountIndex
so that this works.)
@@ -406,7 +406,7 @@ public class SDKSynchronizer: Synchronizer { | |||
} | |||
|
|||
guard let proposal = try await transactionEncoder.proposeShielding( | |||
accountIndex: Int(spendingKey.account), | |||
account: 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.
account: account, | |
accountIndex: accountIndex, |
@@ -441,7 +441,7 @@ public class SDKSynchronizer: Synchronizer { | |||
} | |||
|
|||
let proposal = try await transactionEncoder.proposeTransfer( | |||
accountIndex: Int(spendingKey.account), | |||
account: Zip32Account(Int32(spendingKey.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.
account: Zip32Account(Int32(spendingKey.account)), | |
accountIndex: spendingKey.accountIndex, |
/// - Parameter numberOfAccounts: the number of accounts to use. Multiple accounts are not fully | ||
/// supported so the default value of 1 is recommended. |
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 check that this is correct.
/// - Parameter numberOfAccounts: the number of accounts to use. Multiple accounts are not fully | |
/// supported so the default value of 1 is recommended. | |
/// - Parameter accountIndex: the ZIP 32 index of the account |
public func deriveUnifiedSpendingKey(seed: [UInt8], accountIndex: Int32) throws -> UnifiedSpendingKey { | ||
guard accountIndex >= 0 else { | ||
throw ZcashError.derivationToolInvalidAccount | ||
} | ||
|
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.
Delete derivationToolInvalidAccount
if there are no more occurrences.
public func deriveUnifiedSpendingKey(seed: [UInt8], accountIndex: Int32) throws -> UnifiedSpendingKey { | |
guard accountIndex >= 0 else { | |
throw ZcashError.derivationToolInvalidAccount | |
} | |
public func deriveUnifiedSpendingKey(seed: [UInt8], accountIndex: Zip32AccountIndex) throws -> UnifiedSpendingKey { |
/// - Throws: | ||
/// - `derivationToolInvalidAccount` if the `accountIndex` is invalid. | ||
/// - `derivationToolInvalidAccount` if the `account` is invalid. |
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.
/// - `derivationToolInvalidAccount` if the `account` is invalid. |
public func deriveArbitraryAccountKey(contextString: [UInt8], seed: [UInt8], accountIndex: Int32) throws -> [UInt8] { | ||
guard accountIndex >= 0 else { | ||
throw ZcashError.derivationToolInvalidAccount | ||
} | ||
|
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.
Delete derivationToolInvalidAccount
if there are no more occurrences.
public func deriveArbitraryAccountKey(contextString: [UInt8], seed: [UInt8], accountIndex: Int32) throws -> [UInt8] { | |
guard accountIndex >= 0 else { | |
throw ZcashError.derivationToolInvalidAccount | |
} | |
public func deriveArbitraryAccountKey(contextString: [UInt8], seed: [UInt8], accountIndex: Zip32AccountIndex) throws -> [UInt8] { |
/// - Throws: | ||
/// - `derivationToolInvalidAccount` if the `accountIndex` is invalid. | ||
/// - `derivationToolInvalidAccount` if the `account` is invalid. |
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.
/// - `derivationToolInvalidAccount` if the `account` is invalid. |
@@ -140,13 +141,16 @@ public class DerivationTool: KeyDeriving { | |||
/// | |||
/// - Parameter contextString: a globally-unique non-empty sequence of at most 252 bytes that identifies the desired context. | |||
/// - Parameter seed: `[Uint8]` seed bytes | |||
/// - Parameter accountNumber: `Int` with the account number | |||
/// - Parameter accountIndex: `Int32` with the account number |
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.
/// - Parameter accountIndex: `Int32` with the account number | |
/// - Parameter accountIndex: the ZIP 32 index of the account |
@@ -113,7 +113,7 @@ class PaymentURIFulfillmentTests: ZcashTestCase { | |||
do { | |||
let proposal = try await coordinator.synchronizer.proposefulfillingPaymentURI( | |||
paymentURI, | |||
accountIndex: 0 | |||
account: Account(0) |
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.
account: Account(0) | |
accountIndex: Zip32AccountIndex(0) |
@@ -320,7 +320,7 @@ class PaymentURIFulfillmentTests: ZcashTestCase { | |||
do { | |||
_ = try await coordinator.synchronizer.proposefulfillingPaymentURI( | |||
paymentURI, | |||
accountIndex: 0 | |||
account: Account(0) |
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.
account: Account(0) | |
accountIndex: Zip32AccountIndex(0) |
@@ -86,6 +86,8 @@ class ShieldFundsTests: ZcashTestCase { | |||
/// verify that the shielded transactions are confirmed | |||
/// | |||
func testShieldFunds() async throws { | |||
let account = Account(0) |
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.
let account = Account(0) | |
let accountIndex: Zip32AccountIndex(0) |
@@ -99,7 +101,7 @@ class ShieldFundsTests: ZcashTestCase { | |||
var initialTotalBalance = Zatoshi(-1) | |||
var initialVerifiedBalance = Zatoshi(-1) | |||
|
|||
var initialTransparentBalance: Zatoshi = try await coordinator.synchronizer.getAccountBalance(accountIndex: 0)?.unshielded ?? .zero | |||
var initialTransparentBalance: Zatoshi = try await coordinator.synchronizer.getAccountBalance(account: account)?.unshielded ?? .zero |
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.
var initialTransparentBalance: Zatoshi = try await coordinator.synchronizer.getAccountBalance(account: account)?.unshielded ?? .zero | |
var initialTransparentBalance: Zatoshi = try await coordinator.synchronizer.getAccountBalance(accountIndex: accountIndex)?.unshielded ?? .zero |
initialVerifiedBalance = try await synchronizer.getAccountBalance(account: account)?.saplingBalance.spendableValue ?? .zero | ||
initialTotalBalance = try await synchronizer.getAccountBalance(account: account)?.saplingBalance.total() ?? .zero |
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.
initialVerifiedBalance = try await synchronizer.getAccountBalance(account: account)?.saplingBalance.spendableValue ?? .zero | |
initialTotalBalance = try await synchronizer.getAccountBalance(account: account)?.saplingBalance.total() ?? .zero | |
initialVerifiedBalance = try await synchronizer.getAccountBalance(accountIndex: accountIndex)?.saplingBalance.spendableValue ?? .zero | |
initialTotalBalance = try await synchronizer.getAccountBalance(accountIndex: accountIndex)?.saplingBalance.total() ?? .zero |
@@ -142,7 +144,7 @@ class ShieldFundsTests: ZcashTestCase { | |||
// at this point the balance should be all zeroes for transparent and shielded funds | |||
XCTAssertEqual(initialTotalBalance, Zatoshi.zero) | |||
XCTAssertEqual(initialVerifiedBalance, Zatoshi.zero) | |||
initialTransparentBalance = (try? await coordinator.synchronizer.getAccountBalance(accountIndex: 0))?.unshielded ?? .zero | |||
initialTransparentBalance = (try? await coordinator.synchronizer.getAccountBalance(account: account))?.unshielded ?? .zero |
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.
initialTransparentBalance = (try? await coordinator.synchronizer.getAccountBalance(account: account))?.unshielded ?? .zero | |
initialTransparentBalance = (try? await coordinator.synchronizer.getAccountBalance(accountIndex: accountIndex))?.unshielded ?? .zero |
@@ -175,7 +177,7 @@ class ShieldFundsTests: ZcashTestCase { | |||
|
|||
// at this point the balance should be zero for shielded, then zero verified transparent funds | |||
// and 10000 zatoshi of total (not verified) transparent funds. | |||
let tFundsDetectedBalance = try await coordinator.synchronizer.getAccountBalance(accountIndex: 0)?.unshielded ?? .zero | |||
let tFundsDetectedBalance = try await coordinator.synchronizer.getAccountBalance(account: account)?.unshielded ?? .zero |
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.
let tFundsDetectedBalance = try await coordinator.synchronizer.getAccountBalance(account: account)?.unshielded ?? .zero | |
let tFundsDetectedBalance = try await coordinator.synchronizer.getAccountBalance(accountIndex: accountIndex)?.unshielded ?? .zero |
@@ -204,7 +206,7 @@ class ShieldFundsTests: ZcashTestCase { | |||
await fulfillment(of: [tFundsConfirmationSyncExpectation], timeout: 5) | |||
|
|||
// the transparent funds should be 10000 zatoshis both total and verified | |||
let confirmedTFundsBalance = try await coordinator.synchronizer.getAccountBalance(accountIndex: 0)?.unshielded ?? .zero | |||
let confirmedTFundsBalance = try await coordinator.synchronizer.getAccountBalance(account: account)?.unshielded ?? .zero |
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.
let confirmedTFundsBalance = try await coordinator.synchronizer.getAccountBalance(account: account)?.unshielded ?? .zero | |
let confirmedTFundsBalance = try await coordinator.synchronizer.getAccountBalance(accountIndex: accountIndex)?.unshielded ?? .zero |
@@ -235,7 +237,7 @@ class ShieldFundsTests: ZcashTestCase { | |||
|
|||
guard shouldContinue else { return } | |||
|
|||
let postShieldingBalance = try await coordinator.synchronizer.getAccountBalance(accountIndex: 0)?.unshielded ?? .zero | |||
let postShieldingBalance = try await coordinator.synchronizer.getAccountBalance(account: account)?.unshielded ?? .zero |
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.
let postShieldingBalance = try await coordinator.synchronizer.getAccountBalance(account: account)?.unshielded ?? .zero | |
let postShieldingBalance = try await coordinator.synchronizer.getAccountBalance(accountIndex: accountIndex)?.unshielded ?? .zero |
@@ -288,7 +290,7 @@ class ShieldFundsTests: ZcashTestCase { | |||
|
|||
// Now it should verify that the balance has been shielded. The resulting balance should be zero | |||
// transparent funds and `10000 - fee` total shielded funds, zero verified shielded funds. | |||
let postShieldingShieldedBalance = try await coordinator.synchronizer.getAccountBalance(accountIndex: 0)?.unshielded ?? .zero | |||
let postShieldingShieldedBalance = try await coordinator.synchronizer.getAccountBalance(account: account)?.unshielded ?? .zero |
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.
let postShieldingShieldedBalance = try await coordinator.synchronizer.getAccountBalance(account: account)?.unshielded ?? .zero | |
let postShieldingShieldedBalance = try await coordinator.synchronizer.getAccountBalance(accountIndex: accountIndex)?.unshielded ?? .zero |
@@ -330,7 +332,7 @@ class ShieldFundsTests: ZcashTestCase { | |||
|
|||
expectedBalance = try await coordinator.synchronizer.getAccountBalance()?.saplingBalance.total() ?? .zero | |||
XCTAssertEqual(expectedBalance, Zatoshi(9000)) | |||
let postShieldingConfirmationShieldedBalance = try await coordinator.synchronizer.getAccountBalance(accountIndex: 0)?.unshielded ?? .zero | |||
let postShieldingConfirmationShieldedBalance = try await coordinator.synchronizer.getAccountBalance(account: account)?.unshielded ?? .zero |
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.
let postShieldingConfirmationShieldedBalance = try await coordinator.synchronizer.getAccountBalance(account: account)?.unshielded ?? .zero | |
let postShieldingConfirmationShieldedBalance = try await coordinator.synchronizer.getAccountBalance(accountIndex: accountIndex)?.unshielded ?? .zero |
synchronizerMock.getSaplingAddressAccountClosure = { account in | ||
XCTAssertEqual(account, Account(3)) |
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.
synchronizerMock.getSaplingAddressAccountClosure = { account in | |
XCTAssertEqual(account, Account(3)) | |
synchronizerMock.getSaplingAddressAccountIndexClosure = { accountIndex in | |
XCTAssertEqual(accountIndex, Zip32AccountIndex(3)) |
and similarly below.
let testAccount = Account(3) | ||
|
||
synchronizerMock.getSaplingAddressAccountClosure = { account in | ||
XCTAssertEqual(account, testAccount) |
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.
let testAccount = Account(3) | |
synchronizerMock.getSaplingAddressAccountClosure = { account in | |
XCTAssertEqual(account, testAccount) | |
let testAccountIndex = Zip32AccountIndex(3) | |
synchronizerMock.getSaplingAddressAccountIndexClosure = { accountIndex in | |
XCTAssertEqual(accountIndex, testAccountIndex) |
and similarly below.
@@ -53,7 +53,7 @@ class DerivationToolMainnetTests: XCTestCase { | |||
func testDeriveViewingKeysFromSeed() throws { | |||
let seedBytes = [UInt8](seedData) | |||
|
|||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: 0) | |||
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, account: Account(0)) |
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.
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, account: Account(0)) | |
let spendingKey = try derivationTool.deriveUnifiedSpendingKey(seed: seedBytes, accountIndex: Zip32AccountIndex(0)) |
and similarly below.
@@ -86,7 +86,7 @@ class TestCoordinator { | |||
|
|||
self.spendingKey = try derivationTool.deriveUnifiedSpendingKey( | |||
seed: Environment.seedBytes, | |||
accountIndex: 0 | |||
account: Account(0) |
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.
account: Account(0) | |
accountIndex: Zip32AccountIndex(0) |
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.
Changes requested.
Closes #1511
DerivationTool
uses accountIndex: Int32from_account_id
/to_account_id
refactored to AccountId(Int)This code review checklist is intended to serve as a starting point for the author and reviewer, although it may not be appropriate for all types of changes (e.g. fixing a spelling typo in documentation). For more in-depth discussion of how we think about code review, please see Code Review Guidelines.
Author
Reviewer