Skip to content

Commit 76edf02

Browse files
committed
Allow direct reference using the current app
1 parent 165724d commit 76edf02

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

data/transactions/logic/eval.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2804,6 +2804,15 @@ func appReference(cx *evalContext, ref uint64, foreign bool) (basics.AppIndex, e
28042804
return appID, nil
28052805
}
28062806
}
2807+
// It should be legal to use your own app id, which
2808+
// can't be in ForeignApps during creation, because it
2809+
// is unknown then. But it can be discovered in the
2810+
// app code. It's tempting to combine this with the
2811+
// == 0 test, above, but it must come after the check
2812+
// for being below len(ForeignApps)
2813+
if ref == uint64(cx.Ledger.ApplicationID()) {
2814+
return cx.Ledger.ApplicationID(), nil
2815+
}
28072816
} else {
28082817
// Old rules
28092818
if foreign {

data/transactions/logic/evalStateful_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,11 @@ byte 0x414c474f
950950
testProg(t, strings.Replace(text, "int 1 // account idx", "byte \"aoeuiaoeuiaoeuiaoeuiaoeuiaoeui01\"", -1), directRefEnabledVersion-1,
951951
expect{4, "app_local_get_ex arg 0 wanted type uint64..."})
952952
testApp(t, strings.Replace(text, "int 100 // app id", "int 2", -1), now)
953+
// Next we're testing if the use of the current app's id works
954+
// as a direct reference. The error is because the sender
955+
// account is not opted into 123.
956+
ledger.appID = basics.AppIndex(123)
957+
testApp(t, strings.Replace(text, "int 100 // app id", "int 123", -1), now, "no app for account")
953958
testApp(t, strings.Replace(text, "int 100 // app id", "int 2", -1), pre, "no app for account")
954959
testApp(t, strings.Replace(text, "int 100 // app id", "int 9", -1), now, "invalid App reference 9")
955960
testApp(t, strings.Replace(text, "int 1 // account idx", "byte \"aoeuiaoeuiaoeuiaoeuiaoeuiaoeui00\"", -1), now,
@@ -1107,6 +1112,12 @@ int 4141
11071112
now.Txn.Txn.ApplicationID = 0
11081113
now.Txn.Txn.ForeignApps = []basics.AppIndex{100}
11091114
testApp(t, text, now)
1115+
1116+
// Direct reference to the current app also works
1117+
ledger.appID = basics.AppIndex(100)
1118+
now.Txn.Txn.ForeignApps = []basics.AppIndex{}
1119+
testApp(t, strings.Replace(text, "int 1 // ForeignApps index", "int 100", -1), now)
1120+
testApp(t, strings.Replace(text, "int 1 // ForeignApps index", "global CurrentApplicationID", -1), now)
11101121
}
11111122

11121123
const assetsTestProgram = `int 0//account

0 commit comments

Comments
 (0)