aboutsummaryrefslogtreecommitdiff
path: root/plugin/evm
diff options
context:
space:
mode:
authorAaron Buchwald <[email protected]>2020-11-29 14:38:44 -0500
committerAaron Buchwald <[email protected]>2020-11-29 14:38:44 -0500
commit627bc7f7fd75d385e623c3c5177c5aeb639a0e52 (patch)
treedba8e4bec0043766b5367c7409772fa7b653b539 /plugin/evm
parent1ed9c772e948720b02d38a233c9f63a7a95ee761 (diff)
Address comments
Diffstat (limited to 'plugin/evm')
-rw-r--r--plugin/evm/static_service.go21
-rw-r--r--plugin/evm/vm.go2
-rw-r--r--plugin/evm/vm_test.go6
3 files changed, 25 insertions, 4 deletions
diff --git a/plugin/evm/static_service.go b/plugin/evm/static_service.go
index 1b45939..7b0fa8b 100644
--- a/plugin/evm/static_service.go
+++ b/plugin/evm/static_service.go
@@ -7,15 +7,32 @@ import (
"context"
"encoding/json"
+ "github.com/ava-labs/avalanchego/utils/formatting"
"github.com/ava-labs/coreth/core"
)
// StaticService defines the static API services exposed by the evm
type StaticService struct{}
+// BuildGenesisReply is the reply from BuildGenesis
+type BuildGenesisReply struct {
+ Bytes string `json:"bytes"`
+ Encoding formatting.Encoding `json:"encoding"`
+}
+
// BuildGenesis returns the UTXOs such that at least one address in [args.Addresses] is
// referenced in the UTXO.
-func (*StaticService) BuildGenesis(_ context.Context, args *core.Genesis) ([]byte, error) {
+func (*StaticService) BuildGenesis(_ context.Context, args *core.Genesis) (*BuildGenesisReply, error) {
bytes, err := json.Marshal(args)
- return bytes, err
+ if err != nil {
+ return nil, err
+ }
+ bytesStr, err := formatting.Encode(formatting.Hex, bytes)
+ if err != nil {
+ return nil, err
+ }
+ return &BuildGenesisReply{
+ Bytes: bytesStr,
+ Encoding: formatting.Hex,
+ }, nil
}
diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go
index aaf7f10..58ab600 100644
--- a/plugin/evm/vm.go
+++ b/plugin/evm/vm.go
@@ -131,9 +131,9 @@ func init() {
c.RegisterType(&secp256k1fx.Credential{}),
c.RegisterType(&secp256k1fx.Input{}),
c.RegisterType(&secp256k1fx.OutputOwners{}),
+ Codec.RegisterCodec(codecVersion, c),
)
- errs.Add(Codec.RegisterCodec(0, c))
if errs.Errored() {
panic(errs.Err)
}
diff --git a/plugin/evm/vm_test.go b/plugin/evm/vm_test.go
index 1b894ce..2993b3b 100644
--- a/plugin/evm/vm_test.go
+++ b/plugin/evm/vm_test.go
@@ -63,10 +63,14 @@ func BuildGenesisTest(t *testing.T) []byte {
if err := json.Unmarshal([]byte(genesisJSON), genesis); err != nil {
t.Fatalf("Problem unmarshaling genesis JSON: %s", err)
}
- genesisBytes, err := ss.BuildGenesis(nil, genesis)
+ genesisReply, err := ss.BuildGenesis(nil, genesis)
if err != nil {
t.Fatalf("Failed to create test genesis")
}
+ genesisBytes, err := formatting.Decode(genesisReply.Encoding, genesisReply.Bytes)
+ if err != nil {
+ t.Fatalf("Failed to decode genesis bytes: %w", err)
+ }
return genesisBytes
}