Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
ebef4e10
Commit
ebef4e10
authored
Jan 03, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ether
parent
a42ebd9e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
11 deletions
+52
-11
contract.go
contract.go
+52
-11
No files found.
contract.go
View file @
ebef4e10
package
main
package
main
import
(
import
(
_
"fmt"
)
)
type
Contract
struct
{
type
Contract
struct
{
active
int
t
uint32
// contract is always 1
amount
uint
32
// ???
amount
uint
64
// ???
state
*
Trie
state
*
Trie
}
}
func
NewContract
(
amount
uint32
,
root
[]
byte
)
*
Contract
{
contract
:=
&
Contract
{
active
:
1
,
amount
:
amount
}
func
NewContract
(
amount
uint64
,
root
[]
byte
)
*
Contract
{
contract
:=
&
Contract
{
t
:
1
,
amount
:
amount
}
contract
.
state
=
NewTrie
(
Db
,
string
(
root
))
contract
.
state
=
NewTrie
(
Db
,
string
(
root
))
return
contract
return
contract
}
}
func
(
c
*
Contract
)
MarshalRlp
()
[]
byte
{
// Prepare the transaction for serialization
preEnc
:=
[]
interface
{}{
uint32
(
c
.
active
),
c
.
amount
,
c
.
state
.
root
}
return
Encode
(
preEnc
)
func
(
c
*
Contract
)
MarshalRlp
()
[]
byte
{
return
Encode
([]
interface
{}{
c
.
t
,
c
.
amount
,
c
.
state
.
root
})
}
}
func
(
c
*
Contract
)
UnmarshalRlp
(
data
[]
byte
)
{
func
(
c
*
Contract
)
UnmarshalRlp
(
data
[]
byte
)
{
t
,
_
:=
Decode
(
data
,
0
)
t
,
_
:=
Decode
(
data
,
0
)
if
slice
,
ok
:=
t
.
([]
interface
{});
ok
{
if
slice
,
ok
:=
t
.
([]
interface
{});
ok
{
if
active
,
ok
:=
slice
[
0
]
.
(
uint8
);
ok
{
if
t
,
ok
:=
slice
[
0
]
.
(
uint8
);
ok
{
c
.
active
=
int
(
active
)
c
.
t
=
uint32
(
t
)
}
}
if
amount
,
ok
:=
slice
[
1
]
.
(
uint8
);
ok
{
if
amount
,
ok
:=
slice
[
1
]
.
(
uint8
);
ok
{
c
.
amount
=
uint32
(
amount
)
c
.
amount
=
uint64
(
amount
)
}
else
if
amount
,
ok
:=
slice
[
1
]
.
(
uint16
);
ok
{
c
.
amount
=
uint64
(
amount
)
}
else
if
amount
,
ok
:=
slice
[
1
]
.
(
uint32
);
ok
{
c
.
amount
=
uint64
(
amount
)
}
else
if
amount
,
ok
:=
slice
[
1
]
.
(
uint64
);
ok
{
c
.
amount
=
amount
}
}
if
root
,
ok
:=
slice
[
2
]
.
([]
uint8
);
ok
{
if
root
,
ok
:=
slice
[
2
]
.
([]
uint8
);
ok
{
...
@@ -38,3 +44,38 @@ func (c *Contract) UnmarshalRlp(data []byte) {
...
@@ -38,3 +44,38 @@ func (c *Contract) UnmarshalRlp(data []byte) {
}
}
}
}
}
}
type
Ether
struct
{
t
uint32
amount
uint64
nonce
string
}
func
NewEtherFromData
(
data
[]
byte
)
*
Ether
{
ether
:=
&
Ether
{}
ether
.
UnmarshalRlp
(
data
)
return
ether
}
func
(
e
*
Ether
)
MarshalRlp
()
[]
byte
{
return
Encode
([]
interface
{}{
e
.
t
,
e
.
amount
,
e
.
nonce
})
}
func
(
e
*
Ether
)
UnmarshalRlp
(
data
[]
byte
)
{
t
,
_
:=
Decode
(
data
,
0
)
if
slice
,
ok
:=
t
.
([]
interface
{});
ok
{
if
t
,
ok
:=
slice
[
0
]
.
(
uint8
);
ok
{
e
.
t
=
uint32
(
t
)
}
if
amount
,
ok
:=
slice
[
1
]
.
(
uint8
);
ok
{
e
.
amount
=
uint64
(
amount
)
}
if
nonce
,
ok
:=
slice
[
2
]
.
([]
uint8
);
ok
{
e
.
nonce
=
string
(
nonce
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment