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
dca9ee79
Commit
dca9ee79
authored
Dec 27, 2013
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed Tx serialization to return bytes instead of a string
parent
8301d154
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
11 deletions
+13
-11
serialization.go
serialization.go
+6
-2
transaction.go
transaction.go
+7
-9
No files found.
serialization.go
View file @
dca9ee79
...
...
@@ -28,6 +28,10 @@ func NumToVarInt(x int) string {
func
RlpEncode
(
object
interface
{})
string
{
if
str
,
ok
:=
object
.
(
string
);
ok
{
return
"
\x00
"
+
NumToVarInt
(
len
(
str
))
+
str
}
else
if
num
,
ok
:=
object
.
(
uint32
);
ok
{
return
RlpEncode
(
Uitoa
(
num
))
}
else
if
byt
,
ok
:=
object
.
([]
byte
);
ok
{
return
RlpEncode
(
string
(
byt
))
}
else
if
slice
,
ok
:=
object
.
([]
interface
{});
ok
{
var
buffer
bytes
.
Buffer
for
_
,
val
:=
range
slice
{
...
...
@@ -53,7 +57,7 @@ func RlpEncode(object interface{}) string {
}
type
RlpSerializer
interface
{
MarshalRl
s
()
[]
byte
UnmarshalRl
s
([]
byte
)
MarshalRl
p
()
[]
byte
UnmarshalRl
p
([]
byte
)
}
transaction.go
View file @
dca9ee79
...
...
@@ -6,7 +6,6 @@ import (
"encoding/hex"
"crypto/sha256"
_
"bytes"
"strconv"
)
/*
...
...
@@ -35,14 +34,17 @@ var Period3Reward *big.Int = new(big.Int)
var
Period4Reward
*
big
.
Int
=
new
(
big
.
Int
)
type
Transaction
struct
{
RlpSerializer
sender
string
recipient
uint32
value
uint32
fee
uint32
data
[]
string
memory
[]
int
signature
string
// To be removed
signature
string
addr
string
}
...
...
@@ -61,18 +63,14 @@ func NewTransaction(to uint32, value uint32, data []string) *Transaction {
tx
.
data
[
i
]
=
instr
}
b
:=
[]
byte
(
tx
.
Serialize
())
b
:=
[]
byte
(
tx
.
MarshalRlp
())
hash
:=
sha256
.
Sum256
(
b
)
tx
.
addr
=
hex
.
EncodeToString
(
hash
[
0
:
19
])
return
&
tx
}
func
Uitoa
(
i
uint32
)
string
{
return
strconv
.
FormatUint
(
uint64
(
i
),
10
)
}
func
(
tx
*
Transaction
)
Serialize
()
string
{
func
(
tx
*
Transaction
)
MarshalRlp
()
[]
byte
{
// Prepare the transaction for serialization
preEnc
:=
[]
interface
{}{
"0"
,
// TODO last Tx
...
...
@@ -84,7 +82,7 @@ func (tx *Transaction) Serialize() string {
tx
.
data
,
}
return
RlpEncode
(
preEnc
)
return
[]
byte
(
RlpEncode
(
preEnc
)
)
}
func
InitFees
()
{
...
...
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