@@ -596,8 +596,19 @@ func (h *SendPublicPaymentIntentHandler) validateActions(
596
596
}
597
597
598
598
// Code->Code public ayments can only be made to primary or pool accounts
599
+ // that are open and managed by Code
599
600
switch h .cachedDestinationAccountInfoRecord .AccountType {
600
601
case commonpb .AccountType_PRIMARY , commonpb .AccountType_POOL :
602
+ timelockRecord , err := h .data .GetTimelockByVault (ctx , destination .PublicKey ().ToBase58 ())
603
+ if err != nil {
604
+ return err
605
+ }
606
+ if ! common .IsManagedByCode (ctx , timelockRecord ) {
607
+ if timelockRecord .IsClosed () {
608
+ return NewStaleStateError ("destination account has been closed" )
609
+ }
610
+ return ErrDestinationNotManagedByCode
611
+ }
601
612
default :
602
613
return NewIntentValidationError ("destination account must be a PRIMARY or POOL account" )
603
614
}
@@ -1381,7 +1392,7 @@ func validateAllUserAccountsManagedByCode(ctx context.Context, initiatorAccounts
1381
1392
// Try to unlock *ANY* latest account, and you're done
1382
1393
for _ , accountRecords := range initiatorAccounts {
1383
1394
if ! accountRecords .IsManagedByCode (ctx ) {
1384
- return ErrNotManagedByCode
1395
+ return ErrSourceNotManagedByCode
1385
1396
}
1386
1397
}
1387
1398
@@ -1683,15 +1694,14 @@ func validateClaimedGiftCard(ctx context.Context, data code_data.Provider, giftC
1683
1694
return err
1684
1695
}
1685
1696
1686
- isManagedByCode := common .IsManagedByCode (ctx , timelockRecord )
1687
- if ! isManagedByCode {
1697
+ if ! common .IsManagedByCode (ctx , timelockRecord ) {
1688
1698
if timelockRecord .IsClosed () {
1689
1699
// Better error messaging, since we know we'll never reopen the account
1690
1700
// and the balance is guaranteed to be claimed (not necessarily through
1691
1701
// Code server though).
1692
1702
return NewStaleStateError ("gift card balance has already been claimed" )
1693
1703
}
1694
- return ErrNotManagedByCode
1704
+ return ErrSourceNotManagedByCode
1695
1705
}
1696
1706
1697
1707
//
@@ -1732,33 +1742,32 @@ func validateDistributedPool(ctx context.Context, data code_data.Provider, poolV
1732
1742
}
1733
1743
1734
1744
//
1735
- // Part 2: Is the full amount being distributed ?
1745
+ // Part 2: Is the pool account managed by Code ?
1736
1746
//
1737
1747
1738
- poolBalance , err := balance . CalculateFromCache (ctx , data , poolVaultAccount )
1748
+ timelockRecord , err := data . GetTimelockByVault (ctx , poolVaultAccount . PublicKey (). ToBase58 () )
1739
1749
if err != nil {
1740
1750
return err
1741
- } else if poolBalance == 0 {
1742
- return NewStaleStateError ("pool balance has already been distributed" )
1743
- } else if distributedAmount != poolBalance {
1744
- return NewIntentValidationErrorf ("must distribute entire pool balance of %d quarks" , poolBalance )
1751
+ }
1752
+
1753
+ if ! common .IsManagedByCode (ctx , timelockRecord ) {
1754
+ if timelockRecord .IsClosed () {
1755
+ return NewStaleStateError ("pool balance has already been distributed" )
1756
+ }
1757
+ return ErrSourceNotManagedByCode
1745
1758
}
1746
1759
1747
1760
//
1748
- // Part 3: Is the pool account managed by Code ?
1761
+ // Part 3: Is the full amount being distributed ?
1749
1762
//
1750
1763
1751
- timelockRecord , err := data . GetTimelockByVault (ctx , poolVaultAccount . PublicKey (). ToBase58 () )
1764
+ poolBalance , err := balance . CalculateFromCache (ctx , data , poolVaultAccount )
1752
1765
if err != nil {
1753
1766
return err
1754
- }
1755
-
1756
- isManagedByCode := common .IsManagedByCode (ctx , timelockRecord )
1757
- if ! isManagedByCode {
1758
- if timelockRecord .IsClosed () {
1759
- return NewStaleStateError ("pool balance has already been distributed" )
1760
- }
1761
- return ErrNotManagedByCode
1767
+ } else if poolBalance == 0 {
1768
+ return NewStaleStateError ("pool balance has already been distributed" )
1769
+ } else if distributedAmount != poolBalance {
1770
+ return NewIntentValidationErrorf ("must distribute entire pool balance of %d quarks" , poolBalance )
1762
1771
}
1763
1772
1764
1773
return nil
0 commit comments