good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
dca9ee79
Commit
dca9ee79
authored
Dec 27, 2013
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Changed Tx serialization to return bytes instead of a string
parent
8301d154
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
serialization.go
+6
-2
6 additions, 2 deletions
serialization.go
transaction.go
+7
-9
7 additions, 9 deletions
transaction.go
with
13 additions
and
11 deletions
serialization.go
+
6
−
2
View file @
dca9ee79
...
@@ -28,6 +28,10 @@ func NumToVarInt(x int) string {
...
@@ -28,6 +28,10 @@ func NumToVarInt(x int) string {
func
RlpEncode
(
object
interface
{})
string
{
func
RlpEncode
(
object
interface
{})
string
{
if
str
,
ok
:=
object
.
(
string
);
ok
{
if
str
,
ok
:=
object
.
(
string
);
ok
{
return
"
\x00
"
+
NumToVarInt
(
len
(
str
))
+
str
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
{
}
else
if
slice
,
ok
:=
object
.
([]
interface
{});
ok
{
var
buffer
bytes
.
Buffer
var
buffer
bytes
.
Buffer
for
_
,
val
:=
range
slice
{
for
_
,
val
:=
range
slice
{
...
@@ -53,7 +57,7 @@ func RlpEncode(object interface{}) string {
...
@@ -53,7 +57,7 @@ func RlpEncode(object interface{}) string {
}
}
type
RlpSerializer
interface
{
type
RlpSerializer
interface
{
MarshalRl
s
()
[]
byte
MarshalRl
p
()
[]
byte
UnmarshalRl
s
([]
byte
)
UnmarshalRl
p
([]
byte
)
}
}
This diff is collapsed.
Click to expand it.
transaction.go
+
7
−
9
View file @
dca9ee79
...
@@ -6,7 +6,6 @@ import (
...
@@ -6,7 +6,6 @@ import (
"encoding/hex"
"encoding/hex"
"crypto/sha256"
"crypto/sha256"
_
"bytes"
_
"bytes"
"strconv"
)
)
/*
/*
...
@@ -35,14 +34,17 @@ var Period3Reward *big.Int = new(big.Int)
...
@@ -35,14 +34,17 @@ var Period3Reward *big.Int = new(big.Int)
var
Period4Reward
*
big
.
Int
=
new
(
big
.
Int
)
var
Period4Reward
*
big
.
Int
=
new
(
big
.
Int
)
type
Transaction
struct
{
type
Transaction
struct
{
RlpSerializer
sender
string
sender
string
recipient
uint32
recipient
uint32
value
uint32
value
uint32
fee
uint32
fee
uint32
data
[]
string
data
[]
string
memory
[]
int
memory
[]
int
signature
string
// To be removed
signature
string
addr
string
addr
string
}
}
...
@@ -61,18 +63,14 @@ func NewTransaction(to uint32, value uint32, data []string) *Transaction {
...
@@ -61,18 +63,14 @@ func NewTransaction(to uint32, value uint32, data []string) *Transaction {
tx
.
data
[
i
]
=
instr
tx
.
data
[
i
]
=
instr
}
}
b
:=
[]
byte
(
tx
.
Serialize
())
b
:=
[]
byte
(
tx
.
MarshalRlp
())
hash
:=
sha256
.
Sum256
(
b
)
hash
:=
sha256
.
Sum256
(
b
)
tx
.
addr
=
hex
.
EncodeToString
(
hash
[
0
:
19
])
tx
.
addr
=
hex
.
EncodeToString
(
hash
[
0
:
19
])
return
&
tx
return
&
tx
}
}
func
Uitoa
(
i
uint32
)
string
{
func
(
tx
*
Transaction
)
MarshalRlp
()
[]
byte
{
return
strconv
.
FormatUint
(
uint64
(
i
),
10
)
}
func
(
tx
*
Transaction
)
Serialize
()
string
{
// Prepare the transaction for serialization
// Prepare the transaction for serialization
preEnc
:=
[]
interface
{}{
preEnc
:=
[]
interface
{}{
"0"
,
// TODO last Tx
"0"
,
// TODO last Tx
...
@@ -84,7 +82,7 @@ func (tx *Transaction) Serialize() string {
...
@@ -84,7 +82,7 @@ func (tx *Transaction) Serialize() string {
tx
.
data
,
tx
.
data
,
}
}
return
RlpEncode
(
preEnc
)
return
[]
byte
(
RlpEncode
(
preEnc
)
)
}
}
func
InitFees
()
{
func
InitFees
()
{
...
...
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