Skip to content

Commit 7232431

Browse files
authored
Merge pull request algorand#2 from ori-shem-tov/feature/asa-global-freeze
update "asset_holding_get" and "asset_params_get" opcodes
2 parents 1d1044d + e0954a4 commit 7232431

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

data/transactions/logic/eval.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,11 +2894,13 @@ func opUncover(cx *EvalContext) error {
28942894
return nil
28952895
}
28962896

2897-
func (cx *EvalContext) assetHoldingToValue(holding *basics.AssetHolding, fs assetHoldingFieldSpec) (sv stackValue, err error) {
2897+
func (cx *EvalContext) assetHoldingToValue(holding *basics.AssetHolding, fs assetHoldingFieldSpec, params *basics.AssetParams) (sv stackValue, err error) {
28982898
switch fs.field {
28992899
case AssetBalance:
29002900
sv.Uint = holding.Amount
29012901
case AssetFrozen:
2902+
sv.Uint = boolToUint(holding.Frozen || params.GlobalFrozen)
2903+
case AccountFrozen:
29022904
sv.Uint = boolToUint(holding.Frozen)
29032905
default:
29042906
return sv, fmt.Errorf("invalid asset_holding_get field %d", fs.field)
@@ -2936,6 +2938,8 @@ func (cx *EvalContext) assetParamsToValue(params *basics.AssetParams, creator ba
29362938
sv.Bytes = params.Clawback[:]
29372939
case AssetCreator:
29382940
sv.Bytes = creator[:]
2941+
case AssetGlobalFrozen:
2942+
sv.Uint = boolToUint(params.GlobalFrozen)
29392943
default:
29402944
return sv, fmt.Errorf("invalid asset_params_get field %d", fs.field)
29412945
}
@@ -4918,12 +4922,15 @@ func opAssetHoldingGet(cx *EvalContext) error {
49184922

49194923
var exist uint64 = 0
49204924
var value stackValue
4921-
if holding, err := cx.Ledger.AssetHolding(addr, asset); err == nil {
4922-
// the holding exists, read the value
4923-
exist = 1
4924-
value, err = cx.assetHoldingToValue(&holding, fs)
4925-
if err != nil {
4926-
return err
4925+
if params, _, err := cx.Ledger.AssetParams(asset); err == nil {
4926+
// params exist, fetch the holding
4927+
if holding, err := cx.Ledger.AssetHolding(addr, asset); err == nil {
4928+
// the holding exists, read the value
4929+
exist = 1
4930+
value, err = cx.assetHoldingToValue(&holding, fs, &params)
4931+
if err != nil {
4932+
return err
4933+
}
49274934
}
49284935
}
49294936

data/transactions/logic/fields.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,11 @@ type AssetHoldingField int
11471147
const (
11481148
// AssetBalance AssetHolding.Amount
11491149
AssetBalance AssetHoldingField = iota
1150-
// AssetFrozen AssetHolding.Frozen
1150+
// AssetFrozen AssetHolding.Frozen || AssetParams.GlobalFrozen
11511151
AssetFrozen
1152+
// AccountFrozen AssetHolding.Frozen
1153+
AccountFrozen
1154+
11521155
invalidAssetHoldingField // compile-time constant for number of fields
11531156
)
11541157

@@ -1180,6 +1183,7 @@ func (fs assetHoldingFieldSpec) Note() string {
11801183
var assetHoldingFieldSpecs = [...]assetHoldingFieldSpec{
11811184
{AssetBalance, StackUint64, 2, "Amount of the asset unit held by this account"},
11821185
{AssetFrozen, StackBoolean, 2, "Is the asset frozen or not"},
1186+
{AccountFrozen, StackBoolean, 12, "Is the account frozen or not"},
11831187
}
11841188

11851189
func assetHoldingFieldSpecByField(f AssetHoldingField) (assetHoldingFieldSpec, bool) {
@@ -1235,6 +1239,9 @@ const (
12351239
// AssetCreator is not *in* the Params, but it is uniquely determined.
12361240
AssetCreator
12371241

1242+
// AssetGlobalFrozen AssetParams.GlobalFrozen
1243+
AssetGlobalFrozen
1244+
12381245
invalidAssetParamsField // compile-time constant for number of fields
12391246
)
12401247

@@ -1276,6 +1283,7 @@ var assetParamsFieldSpecs = [...]assetParamsFieldSpec{
12761283
{AssetFreeze, StackAddress, 2, "Freeze address"},
12771284
{AssetClawback, StackAddress, 2, "Clawback address"},
12781285
{AssetCreator, StackAddress, 5, "Creator address"},
1286+
{AssetGlobalFrozen, StackBoolean, 12, "Is the asset frozen globally or not"},
12791287
}
12801288

12811289
func assetParamsFieldSpecByField(f AssetParamsField) (assetParamsFieldSpec, bool) {

data/transactions/logic/fields_string.go

Lines changed: 8 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)