Skip to content

Commit 17454da

Browse files
committed
Improve OpenAccounts intent no-op checking in error scenarios
1 parent dc53053 commit 17454da

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/code/server/transaction/intent_handler.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,25 @@ func (h *OpenAccountsIntentHandler) IsNoop(ctx context.Context, intentRecord *in
130130
}
131131

132132
var authorityToCheck *common.Account
133+
var tokenAccountToCheck *common.Account
133134
var expectedAccountType commonpb.AccountType
134135
switch typedMetadata.AccountSet {
135136
case transactionpb.OpenAccountsMetadata_USER:
136137
authorityToCheck, err = common.NewAccountFromPublicKeyString(intentRecord.InitiatorOwnerAccount)
137138
if err != nil {
138139
return false, err
139140
}
141+
tokenAccountToCheck, err = common.NewAccountFromProto(openAction.Token)
142+
if err != nil {
143+
return false, err
144+
}
140145
expectedAccountType = commonpb.AccountType_PRIMARY
141146
case transactionpb.OpenAccountsMetadata_POOL:
142-
authorityToCheck, err = common.NewAccountFromProto(actions[0].GetOpenAccount().Authority)
147+
authorityToCheck, err = common.NewAccountFromProto(openAction.Authority)
148+
if err != nil {
149+
return false, err
150+
}
151+
tokenAccountToCheck, err = common.NewAccountFromProto(openAction.Token)
143152
if err != nil {
144153
return false, err
145154
}
@@ -158,7 +167,7 @@ func (h *OpenAccountsIntentHandler) IsNoop(ctx context.Context, intentRecord *in
158167
if !ok {
159168
return false, nil
160169
}
161-
return accountInfoRecord.AccountType == expectedAccountType, nil
170+
return accountInfoRecord.TokenAccount == tokenAccountToCheck.PublicKey().ToBase58() && accountInfoRecord.AccountType == expectedAccountType, nil
162171
}
163172

164173
func (h *OpenAccountsIntentHandler) GetBalanceLocks(ctx context.Context, intentRecord *intent.Record, metadata *transactionpb.Metadata) ([]*intentBalanceLock, error) {

0 commit comments

Comments
 (0)