-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6224 from onflow/bastian/improve-evm-events
[Flow EVM] Improve event emission
- Loading branch information
Showing
15 changed files
with
669 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package events | ||
|
||
import ( | ||
"github.com/onflow/cadence" | ||
gethCommon "github.com/onflow/go-ethereum/common" | ||
) | ||
|
||
// cadenceArrayTypeOfUInt8 is the Cadence type [UInt8] | ||
var cadenceArrayTypeOfUInt8 = cadence.NewVariableSizedArrayType(cadence.UInt8Type) | ||
|
||
// bytesToCadenceUInt8ArrayValue converts bytes into a Cadence array of type UInt8 | ||
func bytesToCadenceUInt8ArrayValue(b []byte) cadence.Array { | ||
values := make([]cadence.Value, len(b)) | ||
for i, v := range b { | ||
values[i] = cadence.NewUInt8(v) | ||
} | ||
return cadence.NewArray(values). | ||
WithType(cadenceArrayTypeOfUInt8) | ||
} | ||
|
||
// cadenceHashType is the Cadence type [UInt8;32] | ||
var cadenceHashType = cadence.NewConstantSizedArrayType(gethCommon.HashLength, cadence.UInt8Type) | ||
|
||
// hashToCadenceArrayValue EVM hash ([32]byte) into a Cadence array of type [UInt8;32] | ||
func hashToCadenceArrayValue(hash gethCommon.Hash) cadence.Array { | ||
values := make([]cadence.Value, len(hash)) | ||
for i, v := range hash { | ||
values[i] = cadence.NewUInt8(v) | ||
} | ||
return cadence.NewArray(values). | ||
WithType(cadenceHashType) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package events | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/onflow/cadence" | ||
gethCommon "github.com/onflow/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBytesToCadenceUInt8ArrayValue(t *testing.T) { | ||
t.Parallel() | ||
|
||
input := []byte{1, 2, 3, 4, 5} | ||
|
||
inCadence := bytesToCadenceUInt8ArrayValue(input) | ||
|
||
require.Equal(t, | ||
cadence.NewArray([]cadence.Value{ | ||
cadence.UInt8(1), | ||
cadence.UInt8(2), | ||
cadence.UInt8(3), | ||
cadence.UInt8(4), | ||
cadence.UInt8(5), | ||
}).WithType(cadenceArrayTypeOfUInt8), | ||
inCadence, | ||
) | ||
} | ||
|
||
func TestHashToCadenceArrayValue(t *testing.T) { | ||
t.Parallel() | ||
|
||
input := gethCommon.Hash{1, 2, 3, 4, 5} | ||
|
||
inCadence := hashToCadenceArrayValue(input) | ||
|
||
require.Equal(t, | ||
cadence.NewArray([]cadence.Value{ | ||
cadence.UInt8(1), | ||
cadence.UInt8(2), | ||
cadence.UInt8(3), | ||
cadence.UInt8(4), | ||
cadence.UInt8(5), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
cadence.UInt8(0), | ||
}).WithType(cadenceHashType), | ||
inCadence, | ||
) | ||
} |
Oops, something went wrong.