Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data/transactions/logic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ Global fields are fields that are common to all the transactions in the group. I
| 7 | LatestTimestamp | uint64 | Last confirmed block UNIX timestamp. Fails if negative. LogicSigVersion >= 2. |
| 8 | CurrentApplicationID | uint64 | ID of current application executing. Fails if no such application is executing. LogicSigVersion >= 2. |
| 9 | CreatorAddress | []byte | Address of the creator of the current application. Fails if no such application is executing. LogicSigVersion >= 3. |
| 10 | GroupID | []byte | ID of the transaction group. Empty if the transaction is not part of a group. LogicSigVersion >= 5. |


**Asset Fields**
Expand Down
1 change: 1 addition & 0 deletions data/transactions/logic/TEAL_opcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ FirstValidTime causes the program to fail. The field is reserved for future use.
| 7 | LatestTimestamp | uint64 | Last confirmed block UNIX timestamp. Fails if negative. LogicSigVersion >= 2. |
| 8 | CurrentApplicationID | uint64 | ID of current application executing. Fails if no such application is executing. LogicSigVersion >= 2. |
| 9 | CreatorAddress | []byte | Address of the creator of the current application. Fails if no such application is executing. LogicSigVersion >= 3. |
| 10 | GroupID | []byte | ID of the transaction group. Empty if the transaction is not part of a group. LogicSigVersion >= 5. |


## gtxn t f
Expand Down
1 change: 1 addition & 0 deletions data/transactions/logic/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@ global Round
global LatestTimestamp
global CurrentApplicationID
global CreatorAddress
global GroupID
txn Sender
txn Fee
bnz label1
Expand Down
1 change: 1 addition & 0 deletions data/transactions/logic/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ var globalFieldDocs = map[string]string{
"LatestTimestamp": "Last confirmed block UNIX timestamp. Fails if negative",
"CurrentApplicationID": "ID of current application executing. Fails if no such application is executing",
"CreatorAddress": "Address of the creator of the current application. Fails if no such application is executing",
"GroupID": "ID of the transaction group. Empty if the transaction is not part of a group.",
}

// GlobalFieldDocs are notes on fields available in `global` with extra versioning info if any
Expand Down
6 changes: 6 additions & 0 deletions data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,10 @@ func (cx *evalContext) getCreatorAddress() ([]byte, error) {
return addr[:], nil
}

func (cx *evalContext) getGroupID() []byte {
return cx.Txn.Txn.Group[:]
}

var zeroAddress basics.Address

func (cx *evalContext) globalFieldToStack(field GlobalField) (sv stackValue, err error) {
Expand All @@ -2256,6 +2260,8 @@ func (cx *evalContext) globalFieldToStack(field GlobalField) (sv stackValue, err
sv.Uint, err = cx.getApplicationID()
case CreatorAddress:
sv.Bytes, err = cx.getCreatorAddress()
case GroupID:
sv.Bytes = cx.getGroupID()
default:
err = fmt.Errorf("invalid global[%d]", field)
}
Expand Down
7 changes: 6 additions & 1 deletion data/transactions/logic/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,11 @@ const globalV4TestProgram = globalV3TestProgram + `
`

const globalV5TestProgram = globalV4TestProgram + `
// No new globals in v5
global GroupID
int 32
bzero
==
&&
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should also have a test where GroupID is not empty...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be doable with some hacking around in evalStateful_test.go, which builds up some groups with two txns in them.

`

func TestGlobal(t *testing.T) {
Expand Down Expand Up @@ -941,6 +945,7 @@ func TestGlobal(t *testing.T) {
CreatorAddress, globalV5TestProgram,
EvalStateful, CheckStateful,
},
6: {GroupID, globalV5TestProgram, Eval, Check},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why does it work, this assumes assembler version 6 but the field defined as version 5 constant

{GroupID, StackBytes, modeAny, 5},

This means the test is never called. I'll submit a PR checking len(tests) <= AssemblerMaxVersion

}
ledger := makeTestLedger(nil)
ledger.appID = 42
Expand Down
6 changes: 6 additions & 0 deletions data/transactions/logic/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ const (
// CreatorAddress [32]byte
CreatorAddress

// v5

// GroupID [32]byte
GroupID

invalidGlobalField
)

Expand Down Expand Up @@ -354,6 +359,7 @@ var globalFieldSpecs = []globalFieldSpec{
{LatestTimestamp, StackUint64, runModeApplication, 2},
{CurrentApplicationID, StackUint64, runModeApplication, 2},
{CreatorAddress, StackBytes, runModeApplication, 3},
{GroupID, StackBytes, modeAny, 5},
}

// GlobalFieldSpecByField maps GlobalField to spec
Expand Down
7 changes: 4 additions & 3 deletions data/transactions/logic/fields_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.