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

Commit

Permalink
Merge pull request #500 from silasdavis/snative-templates
Browse files Browse the repository at this point in the history
Introduce more strongly typed SNatives and contract templates
  • Loading branch information
benjaminbollen authored Feb 22, 2017
2 parents 25baef2 + a48afca commit de0c481
Show file tree
Hide file tree
Showing 20 changed files with 797 additions and 159 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ hell:
go build -o ${REPO}/target/hell ./util/hell/cmd/hell/main.go
./target/hell $(filter-out $@,$(MAKECMDGOALS))

# Dumps Solidity interface contracts for SNatives
.PHONY: snatives
snatives:
@go run ./util/snatives/cmd/main.go

### Building github.com/eris-ltd/eris-db

# build all targets in github.com/eris-ltd/eris-db
Expand Down
25 changes: 6 additions & 19 deletions client/rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,33 +99,20 @@ func Name(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addr,
return tx, nil
}

type PermFunc struct {
Name string
Args string
}

var PermsFuncs = []PermFunc{
{"set_base", "address, permission flag, value"},
{"unset_base", "address, permission flag"},
{"set_global", "permission flag, value"},
{"add_role", "address, role"},
{"rm_role", "address, role"},
}

func Permissions(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey, addrS, nonceS, permFunc string, argsS []string) (*txs.PermissionsTx, error) {
pub, _, nonce, err := checkCommon(nodeClient, keyClient, pubkey, addrS, "0", nonceS)
if err != nil {
return nil, err
}
var args ptypes.PermArgs
switch permFunc {
case "set_base":
case "setBase":
addr, pF, err := decodeAddressPermFlag(argsS[0], argsS[1])
if err != nil {
return nil, err
}
if len(argsS) != 3 {
return nil, fmt.Errorf("set_base also takes a value (true or false)")
return nil, fmt.Errorf("setBase also takes a value (true or false)")
}
var value bool
if argsS[2] == "true" {
Expand All @@ -136,13 +123,13 @@ func Permissions(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey,
return nil, fmt.Errorf("Unknown value %s", argsS[2])
}
args = &ptypes.SetBaseArgs{addr, pF, value}
case "unset_base":
case "unsetBase":
addr, pF, err := decodeAddressPermFlag(argsS[0], argsS[1])
if err != nil {
return nil, err
}
args = &ptypes.UnsetBaseArgs{addr, pF}
case "set_global":
case "setGlobal":
pF, err := ptypes.PermStringToFlag(argsS[0])
if err != nil {
return nil, err
Expand All @@ -156,13 +143,13 @@ func Permissions(nodeClient client.NodeClient, keyClient keys.KeyClient, pubkey,
return nil, fmt.Errorf("Unknown value %s", argsS[1])
}
args = &ptypes.SetGlobalArgs{pF, value}
case "add_role":
case "addRole":
addr, err := hex.DecodeString(argsS[0])
if err != nil {
return nil, err
}
args = &ptypes.AddRoleArgs{addr, argsS[1]}
case "rm_role":
case "removeRole":
addr, err := hex.DecodeString(argsS[0])
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func testPermissions(t *testing.T,
nonceString := ""

_, err := Permissions(nodeClient, keyClient, publicKeyString, addressString,
nonceString, "set_base", []string{permAddressString, "root", "true"})
nonceString, "setBase", []string{permAddressString, "root", "true"})
if err != nil {
t.Logf("Error in PermissionsTx: %s", err)
t.Fail()
Expand Down
2 changes: 1 addition & 1 deletion event/event_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/stretchr/testify/assert"
)

var mockInterval = 10 * time.Millisecond
var mockInterval = 40 * time.Millisecond

type mockSub struct {
subId string
Expand Down
27 changes: 27 additions & 0 deletions manager/eris-mint/evm/abi/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package abi

// Ethereum defines types and calling conventions for the ABI
// (application binary interface) here: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
// We make a start of representing them here

type Type string

type Arg struct {
Name string
Type Type
}

type Return struct {
Name string
Type Type
}

const (
// We don't need to be exhaustive here, just make what we used strongly typed
Address Type = "address"
Int Type = "int"
Uint64 Type = "uint64"
Bytes32 Type = "bytes32"
String Type = "string"
Bool Type = "bool"
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package vm
import (
"fmt"

. "github.com/eris-ltd/eris-db/manager/eris-mint/evm"
"github.com/eris-ltd/eris-db/manager/eris-mint/evm/sha3"
. "github.com/eris-ltd/eris-db/word256"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"reflect"
"testing"

. "github.com/eris-ltd/eris-db/manager/eris-mint/evm"
. "github.com/eris-ltd/eris-db/manager/eris-mint/evm/opcodes"
"github.com/eris-ltd/eris-db/txs"
. "github.com/eris-ltd/eris-db/word256"
Expand Down
3 changes: 3 additions & 0 deletions manager/eris-mint/evm/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func registerNativeContracts() {

type NativeContract func(appState AppState, caller *Account, input []byte, gas *int64) (output []byte, err error)

const FuncIDLength = 4
type FuncID [FuncIDLength]byte

/* Removed due to C dependency
func ecrecoverFunc(appState AppState, caller *Account, input []byte, gas *int64) (output []byte, err error) {
// Deduct gas
Expand Down
3 changes: 3 additions & 0 deletions manager/eris-mint/evm/opcodes/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package opcodes
import (
"fmt"

"github.com/eris-ltd/eris-db/word256"
"gopkg.in/fatih/set.v0"
)

Expand Down Expand Up @@ -378,6 +379,8 @@ func Bytecode(bytelikes ...interface{}) []byte {
if int64(bytes[i]) != b {
panic(fmt.Sprintf("The int64 %v does not fit inside a byte", b))
}
case word256.Word256:
return Concat(bytes[:i], b[:], Bytecode(bytelikes[i+1:]...))
case []byte:
// splice
return Concat(bytes[:i], b, Bytecode(bytelikes[i+1:]...))
Expand Down
Loading

0 comments on commit de0c481

Please sign in to comment.