forked from getamis/sol2proto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapping.go
77 lines (70 loc) · 1.74 KB
/
mapping.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2018 AMIS Technologies
// This file is part of the sol2proto
//
// The sol2proto is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The sol2proto is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the sol2proto. If not, see <http://www.gnu.org/licenses/>.
package grpc
import "github.com/ethereum/go-ethereum/accounts/abi"
func ToGrpcArgument(in abi.Argument) Argument {
arg := Argument{
Name: in.Name,
IsSlice: in.Type.IsSlice,
}
arg.Type = toGrpcType(in.Type)
return arg
}
func toGrpcType(t abi.Type) string {
switch t.T {
case abi.IntTy:
if t.Size == 8 {
return "byte"
} else if t.Size == 32 {
return "int32"
} else if t.Size == 64 {
return "int64"
}
return "bytes"
case abi.UintTy:
if t.Size == 8 {
return "byte"
} else if t.Size == 32 {
return "uint32"
} else if t.Size == 64 {
return "uint64"
}
return "bytes"
case abi.BoolTy:
return "bool"
case abi.StringTy:
return "string"
case abi.AddressTy:
return "string"
case abi.FixedBytesTy:
return "bytes"
case abi.BytesTy:
return "bytes"
case abi.HashTy:
return "string"
case abi.FixedPointTy:
case abi.FunctionTy:
fallthrough
default:
}
return "bytes"
}
func ToMessage(name string, args []Argument) Message {
return Message{
Name: name,
Args: args,
}
}