Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
burrow
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hang Yu
burrow
Commits
a26ec7cf
Unverified
Commit
a26ec7cf
authored
8 years ago
by
Silas Davis
Browse files
Options
Downloads
Patches
Plain Diff
types update
parent
3d1e7ecc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
manager/eris-mint/evm/snative.go
+43
-40
43 additions, 40 deletions
manager/eris-mint/evm/snative.go
manager/eris-mint/evm/snative_test.go
+2
-0
2 additions, 0 deletions
manager/eris-mint/evm/snative_test.go
with
45 additions
and
40 deletions
manager/eris-mint/evm/snative.go
+
43
−
40
View file @
a26ec7cf
...
...
@@ -60,6 +60,8 @@ func registerSNativeContracts() {
// Returns a map of all SNative contracts defined indexed by name
func
SNativeContracts
()
map
[
string
]
SNativeContractDescription
{
permFlagType
:=
SolidityUint64
roleType
:=
SolidityBytes32
contracts
:=
[]
SNativeContractDescription
{
NewSNativeContract
(
`
* Interface for managing Secure Native authorizations.
...
...
@@ -75,7 +77,7 @@ func SNativeContracts() map[string]SNativeContractDescription {
"add_role"
,
[]
SolidityArg
{
arg
(
"_account"
,
SolidityAddress
),
arg
(
"_role"
,
S
ol
idityBytes32
),
arg
(
"_role"
,
r
ol
eType
),
},
ret
(
"result"
,
SolidityBool
),
ptypes
.
AddRole
,
...
...
@@ -90,7 +92,7 @@ func SNativeContracts() map[string]SNativeContractDescription {
"has_role"
,
[]
SolidityArg
{
arg
(
"_account"
,
SolidityAddress
),
arg
(
"_role"
,
S
ol
idityBytes32
),
arg
(
"_role"
,
r
ol
eType
),
},
ret
(
"result"
,
SolidityBool
),
ptypes
.
HasRole
,
...
...
@@ -105,7 +107,7 @@ func SNativeContracts() map[string]SNativeContractDescription {
"rm_role"
,
[]
SolidityArg
{
arg
(
"_account"
,
SolidityAddress
),
arg
(
"_role"
,
S
ol
idityBytes32
),
arg
(
"_role"
,
r
ol
eType
),
},
ret
(
"result"
,
SolidityBool
),
ptypes
.
RmRole
,
...
...
@@ -120,8 +122,8 @@ func SNativeContracts() map[string]SNativeContractDescription {
`
,
"set_base"
,
[]
SolidityArg
{
arg
(
"_account"
,
SolidityAddress
),
arg
(
"_authorization"
,
SolidityInt
),
arg
(
"_value"
,
SolidityInt
)},
arg
(
"_authorization"
,
permFlagType
),
arg
(
"_value"
,
permFlagType
)},
ret
(
"result"
,
SolidityBool
),
ptypes
.
SetBase
,
set_base
},
...
...
@@ -134,7 +136,7 @@ func SNativeContracts() map[string]SNativeContractDescription {
`
,
"has_base"
,
[]
SolidityArg
{
arg
(
"_account"
,
SolidityAddress
),
arg
(
"_authorization"
,
SolidityInt
)},
arg
(
"_authorization"
,
permFlagType
)},
ret
(
"result"
,
SolidityBool
),
ptypes
.
HasBase
,
has_base
},
...
...
@@ -147,8 +149,8 @@ func SNativeContracts() map[string]SNativeContractDescription {
`
,
"unset_base"
,
[]
SolidityArg
{
arg
(
"_account"
,
SolidityAddress
),
arg
(
"_authorization"
,
SolidityInt
)},
ret
(
"authorization"
,
SolidityInt
),
arg
(
"_authorization"
,
permFlagType
)},
ret
(
"authorization"
,
permFlagType
),
ptypes
.
UnsetBase
,
unset_base
},
...
...
@@ -161,9 +163,9 @@ func SNativeContracts() map[string]SNativeContractDescription {
`
,
"set_global"
,
[]
SolidityArg
{
arg
(
"_account"
,
SolidityAddress
),
arg
(
"_authorization"
,
SolidityInt
),
arg
(
"_value"
,
SolidityInt
)},
ret
(
"authorization"
,
SolidityInt
),
arg
(
"_authorization"
,
permFlagType
),
arg
(
"_value"
,
permFlagType
)},
ret
(
"authorization"
,
permFlagType
),
ptypes
.
SetGlobal
,
set_global
},
),
...
...
@@ -197,6 +199,36 @@ func NewSNativeContract(comment, name string, functions ...SNativeFuncDescriptio
}
}
func
(
contract
*
SNativeContractDescription
)
Dispatch
(
appState
AppState
,
caller
*
Account
,
args
[]
byte
,
gas
*
int64
)
(
output
[]
byte
,
err
error
)
{
if
len
(
args
)
<
4
{
return
Zero256
.
Bytes
(),
fmt
.
Errorf
(
"SNatives dispatch requires a 4-byte function "
+
"identifier but arguments are only %s bytes long"
,
len
(
args
))
}
function
,
err
:=
contract
.
FunctionByID
(
firstFourBytes
(
args
))
if
err
!=
nil
{
return
Zero256
.
Bytes
(),
err
}
remainingArgs
:=
args
[
4
:
]
// check if we have permission to call this function
if
!
HasPermission
(
appState
,
caller
,
function
.
PermFlag
)
{
return
Zero256
.
Bytes
(),
ErrInvalidPermission
{
caller
.
Address
,
function
.
Name
}
}
// ensure there are enough arguments
if
len
(
remainingArgs
)
!=
function
.
NArgs
()
*
32
{
return
Zero256
.
Bytes
(),
fmt
.
Errorf
(
"%s() takes %d arguments"
,
function
.
Name
,
function
.
NArgs
())
}
// call the function
return
function
.
F
(
appState
,
caller
,
remainingArgs
,
gas
)
}
func
(
contract
*
SNativeContractDescription
)
Address
()
Word256
{
return
LeftPadWord256
([]
byte
(
contract
.
Name
))
}
...
...
@@ -227,35 +259,6 @@ func (contract *SNativeContractDescription) Functions() []SNativeFuncDescription
return
fs
}
func
(
contract
*
SNativeContractDescription
)
Dispatch
(
appState
AppState
,
caller
*
Account
,
args
[]
byte
,
gas
*
int64
)
(
output
[]
byte
,
err
error
)
{
if
len
(
args
)
<
4
{
return
nil
,
fmt
.
Errorf
(
"SNatives dispatch requires a 4-byte function "
+
"identifier but arguments are only %s bytes long"
,
len
(
args
))
}
function
,
err
:=
contract
.
FunctionByID
(
firstFourBytes
(
args
))
if
err
!=
nil
{
return
nil
,
err
}
remainingArgs
:=
args
[
4
:
]
// check if we have permission to call this function
if
!
HasPermission
(
appState
,
caller
,
function
.
PermFlag
)
{
return
nil
,
ErrInvalidPermission
{
caller
.
Address
,
function
.
Name
}
}
// ensure there are enough arguments
if
len
(
remainingArgs
)
!=
function
.
NArgs
()
*
32
{
return
nil
,
fmt
.
Errorf
(
"%s() takes %d arguments"
,
function
.
Name
,
function
.
NArgs
())
}
// call the function
return
function
.
F
(
appState
,
caller
,
remainingArgs
,
gas
)
}
func
(
contract
*
SNativeContractDescription
)
SolidityComment
()
string
{
return
solidityComment
(
contract
.
Comment
)
}
...
...
This diff is collapsed.
Click to expand it.
manager/eris-mint/evm/snative_test.go
+
2
−
0
View file @
a26ec7cf
...
...
@@ -57,6 +57,8 @@ func TestSNativeFuncTemplate(t *testing.T) {
fmt
.
Println
(
solidity
)
}
// This test checks that we can generate the SNative contract interface and
// prints it to stdout
func
TestSNativeContractTemplate
(
t
*
testing
.
T
)
{
contract
:=
SNativeContracts
()[
"permissions_contract"
]
solidity
,
err
:=
contract
.
Solidity
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment