Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

Commit

Permalink
feat: use struct for pc version (ethereum-optimism#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
therealbytes committed Sep 2, 2023
1 parent 179a594 commit be3f484
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
10 changes: 5 additions & 5 deletions concrete/precompiles/precompile_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var PrecompileRegistry *lib.PrecompileWithABI

var PrecompileRegistryMetadata = PrecompileMetadata{
Name: "PrecompileRegistry",
Version: "0.1.0",
Version: Version{common.Big0, common.Big1, common.Big0},
Author: "The concrete-geth Authors",
Description: "A registry of precompiles indexed by address and name.",
Source: "https://github.com/therealbytes/concrete-geth/tree/concrete/concrete/precompiles/precompile_registry.go",
Expand Down Expand Up @@ -63,9 +63,9 @@ func init() {
}

type FrameworkMetadata = struct {
Name string `json:"name"`
Version string `json:"version"`
Source string `json:"source"`
Name string `json:"name"`
Version Version `json:"version"`
Source string `json:"source"`
}

type getFramework struct {
Expand All @@ -80,7 +80,7 @@ func (p *getFramework) Run(API api.API, input []byte) ([]byte, error) {
return p.CallRunWithArgs(func(API api.API, args []interface{}) ([]interface{}, error) {
metadata := FrameworkMetadata{
"Concrete",
"0.1.0",
Version{common.Big0, common.Big1, common.Big0},
"https://github.com/therealbytes/concrete-geth",
}
return []interface{}{metadata}, nil
Expand Down
5 changes: 3 additions & 2 deletions concrete/precompiles/precompile_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package precompiles

import (
"encoding/json"
"fmt"
"testing"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -67,7 +68,7 @@ func TestPrecompileRegistry(t *testing.T) {
r.NoError(err)
precompileData, ok := _precompileData[0].(PrecompileMetadata)
r.True(ok)
r.EqualValues(expectedMetadata, precompileData)
r.EqualValues(fmt.Sprint(expectedMetadata), fmt.Sprint(precompileData))

// Test getPrecompileByName
input, err = pc.ABI.Pack("getPrecompileByName", expectedMetadata.Name)
Expand Down Expand Up @@ -106,7 +107,7 @@ func TestPrecompileRegistry(t *testing.T) {
for _, pc := range pcs {
if pc.Addr == address {
contains = true
r.EqualValues(expectedMetadata, pc)
r.EqualValues(fmt.Sprint(expectedMetadata), fmt.Sprint(precompileData))
}
}
r.True(contains)
Expand Down
9 changes: 8 additions & 1 deletion concrete/precompiles/precompiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ import (
"encoding/json"
"errors"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/concrete/api"
"github.com/ethereum/go-ethereum/concrete/lib"
)

type Version = struct {
Major *big.Int `json:"major"`
Minor *big.Int `json:"minor"`
Patch *big.Int `json:"patch"`
}

type PrecompileMetadata = struct {
Addr common.Address `json:"addr"`
Name string `json:"name"`
Version string `json:"version"`
Version Version `json:"version"`
Author string `json:"author"`
Description string `json:"description"`
Source string `json:"source"`
Expand Down
4 changes: 2 additions & 2 deletions concrete/precompiles/preimage_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ var (
var (
PreimageRegistryMetadata = PrecompileMetadata{
Name: "PreimageRegistry",
Version: "0.1.0",
Version: Version{common.Big0, common.Big1, common.Big0},
Author: "The concrete-geth Authors",
Description: "A registry of stored preimages indexed by their hash.",
Source: "https://github.com/therealbytes/concrete-geth/tree/concrete/concrete/precompiles/preimage_registry.go",
}
BigPreimageRegistryMetadata = PrecompileMetadata{
Name: "BigPreimageRegistry",
Version: "0.1.0",
Version: Version{common.Big0, common.Big1, common.Big0},
Author: "The concrete-geth Authors",
Description: "A registry of stored preimage merkle trees indexed by their root hash.",
Source: "https://github.com/therealbytes/concrete-geth/tree/concrete/concrete/precompiles/pi_registry.go",
Expand Down
10 changes: 8 additions & 2 deletions concrete/precompiles/sol/PrecompileRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity ^0.8.0;

struct Version {
uint256 major;
uint256 minor;
uint256 patch;
}

struct FrameworkMetadata {
string name;
string version;
Version version;
string source;
}

struct PrecompileMetadata {
address addr;
string name;
string version;
Version version;
string author;
string description;
string source;
Expand Down
2 changes: 1 addition & 1 deletion concrete/precompiles/sol/abi/PrecompileRegistry.abi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"inputs":[],"name":"getFramework","outputs":[{"components":[{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"string","name":"source","type":"string"}],"internalType":"struct FrameworkMetadata","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_addr","type":"address"}],"name":"getPrecompile","outputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"string","name":"author","type":"string"},{"internalType":"string","name":"description","type":"string"},{"internalType":"string","name":"source","type":"string"},{"internalType":"string","name":"ABI","type":"string"}],"internalType":"struct PrecompileMetadata","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"}],"name":"getPrecompileByName","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPrecompiledAddresses","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPrecompiles","outputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"string","name":"author","type":"string"},{"internalType":"string","name":"description","type":"string"},{"internalType":"string","name":"source","type":"string"},{"internalType":"string","name":"ABI","type":"string"}],"internalType":"struct PrecompileMetadata[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"}]
[{"inputs":[],"name":"getFramework","outputs":[{"components":[{"internalType":"string","name":"name","type":"string"},{"components":[{"internalType":"uint256","name":"major","type":"uint256"},{"internalType":"uint256","name":"minor","type":"uint256"},{"internalType":"uint256","name":"patch","type":"uint256"}],"internalType":"struct Version","name":"version","type":"tuple"},{"internalType":"string","name":"source","type":"string"}],"internalType":"struct FrameworkMetadata","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_addr","type":"address"}],"name":"getPrecompile","outputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"string","name":"name","type":"string"},{"components":[{"internalType":"uint256","name":"major","type":"uint256"},{"internalType":"uint256","name":"minor","type":"uint256"},{"internalType":"uint256","name":"patch","type":"uint256"}],"internalType":"struct Version","name":"version","type":"tuple"},{"internalType":"string","name":"author","type":"string"},{"internalType":"string","name":"description","type":"string"},{"internalType":"string","name":"source","type":"string"},{"internalType":"string","name":"ABI","type":"string"}],"internalType":"struct PrecompileMetadata","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"_name","type":"string"}],"name":"getPrecompileByName","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPrecompiledAddresses","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getPrecompiles","outputs":[{"components":[{"internalType":"address","name":"addr","type":"address"},{"internalType":"string","name":"name","type":"string"},{"components":[{"internalType":"uint256","name":"major","type":"uint256"},{"internalType":"uint256","name":"minor","type":"uint256"},{"internalType":"uint256","name":"patch","type":"uint256"}],"internalType":"struct Version","name":"version","type":"tuple"},{"internalType":"string","name":"author","type":"string"},{"internalType":"string","name":"description","type":"string"},{"internalType":"string","name":"source","type":"string"},{"internalType":"string","name":"ABI","type":"string"}],"internalType":"struct PrecompileMetadata[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"}]

0 comments on commit be3f484

Please sign in to comment.