Skip to content

Commit 5c2773d

Browse files
committed
Merge branch 'develop'
2 parents d2af922 + fa6a335 commit 5c2773d

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

api/src/main/java/com/getcode/model/intents/IntentDeposit.kt

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class IntentDeposit(
3737
): IntentDeposit {
3838
val intentId = PublicKey.generate()
3939
val currentTray = organizer.tray.copy()
40-
val startBalance = currentTray.availableBalance
40+
val startSlotBalance = currentTray.slotsBalance
4141

42-
// 1. Move all funds from the incoming
42+
// 1. Move all funds from the primary
4343
// account to appropriate slots
4444

4545
val transfers = currentTray.receive(receivingAccount = source, amount = amount).map { transfer ->
@@ -48,8 +48,7 @@ class IntentDeposit(
4848
intentId = intentId,
4949
amount = transfer.kin,
5050
source = currentTray.cluster(transfer.from),
51-
destination =
52-
currentTray.cluster(transfer.to!!).vaultPublicKey
51+
destination = currentTray.cluster(transfer.to!!).vaultPublicKey
5352
)
5453
}
5554

@@ -62,18 +61,15 @@ class IntentDeposit(
6261
intentId = intentId,
6362
amount = exchange.kin,
6463
source = currentTray.cluster(exchange.from),
65-
destination =
66-
currentTray.cluster(exchange.to!!).vaultPublicKey
67-
// Exchanges always provide destination accounts
64+
destination = currentTray.cluster(exchange.to!!).vaultPublicKey // Exchanges always provide destination accounts
6865
)
6966
}
7067

71-
val endBalance = currentTray.availableBalance
68+
val endSlotBalance = currentTray.slotsBalance
7269

73-
// We're just moving funds from incoming
74-
// account to buckets, the balance
75-
// shouldn't change
76-
if (endBalance != startBalance) {
70+
// Ensure that balances are consistent
71+
// with what we expect these action to do
72+
if (endSlotBalance - startSlotBalance != amount) {
7773
throw IntentReceive.Companion.IntentReceiveException.BalanceMismatchException()
7874
}
7975

api/src/main/java/com/getcode/network/client/Client_Transaction.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,17 +554,20 @@ fun Client.getTransferPreflightAction(amount: Kin): Completable {
554554
// 1. Receive funds from incoming accounts as those
555555
// will rotate more frequently than other types of accounts
556556
val receivedKin = transactionReceiver.receiveFromIncoming(organizer)
557-
557+
Timber.d("received ${receivedKin.quarks} from incoming")
558558
// 2. Pull funds from relationships if there's still funds
559559
// missing in buckets after the receiving from primary
560560
if (receivedKin < neededKin) {
561-
transactionReceiver.receiveFromRelationship(organizer, limit = neededKin - receivedKin)
561+
Timber.d("attempt to pull funds from relationship to get to ${neededKin.quarks}")
562+
val result = transactionReceiver.receiveFromRelationship(organizer, limit = neededKin - receivedKin)
563+
Timber.d("received ${result.quarks} from relationships")
562564
}
563565

564566
// 3. If the amount is still larger than what's available
565567
// in the slots, we'll need to move funds from primary
566568
// deposits into slots after receiving
567569
if (amount > organizer.slotsBalance) {
570+
Timber.d("receive from primary")
568571
receiveFromPrimaryIfWithinLimits(organizer)
569572
} else {
570573
Completable.complete()

api/src/main/java/com/getcode/network/client/TransactionReceiver.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.getcode.network.client
33
import android.content.Context
44
import com.getcode.model.Kin
55
import com.getcode.model.intents.IntentDeposit
6+
import com.getcode.model.intents.IntentPublicTransfer
67
import com.getcode.model.intents.IntentReceive
78
import com.getcode.model.intents.IntentRemoteReceive
89
import com.getcode.network.repository.BalanceRepository
@@ -76,7 +77,7 @@ class TransactionReceiver @Inject constructor(
7677

7778
receivedTotal += relationship.partialBalance
7879

79-
if (intent is IntentDeposit) {
80+
if (intent is IntentPublicTransfer) {
8081
setTray(organizer, intent.resultTray)
8182
}
8283

api/src/main/java/com/getcode/solana/organizer/Tray.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Tray(
3434
get() = incoming.partialBalance
3535

3636
var relationships = RelationshipBox()
37-
private set
37+
internal set
3838

3939
var availableRelationshipBalance: Kin = Kin.fromKin(0)
4040
get() = relationships.publicKeys.values.map { it.partialBalance }

0 commit comments

Comments
 (0)