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
8391d3d4
Commit
8391d3d4
authored
Dec 28, 2013
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Unmarshalling of transactions
parent
c7dc92e1
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
transaction.go
+61
-8
61 additions, 8 deletions
transaction.go
with
61 additions
and
8 deletions
transaction.go
+
61
−
8
View file @
8391d3d4
...
@@ -37,20 +37,22 @@ type Transaction struct {
...
@@ -37,20 +37,22 @@ type Transaction struct {
RlpSerializer
RlpSerializer
sender
string
sender
string
recipient
uint32
recipient
string
value
uint32
value
uint32
fee
uint32
fee
uint32
data
[]
string
data
[]
string
memory
[]
int
memory
[]
int
lastTx
string
// To be removed
// To be removed
signature
string
signature
string
addr
string
addr
string
}
}
func
NewTransaction
(
to
uint32
,
value
uint32
,
data
[]
string
)
*
Transaction
{
func
NewTransaction
(
to
string
,
value
uint32
,
data
[]
string
)
*
Transaction
{
tx
:=
Transaction
{
sender
:
"1234567890"
,
recipient
:
to
,
value
:
value
}
tx
:=
Transaction
{
sender
:
"1234567890"
,
recipient
:
to
,
value
:
value
}
tx
.
fee
=
0
//uint32((ContractFee + MemoryFee * float32(len(tx.data))) * 1e8)
tx
.
fee
=
0
//uint32((ContractFee + MemoryFee * float32(len(tx.data))) * 1e8)
tx
.
lastTx
=
"0"
// Serialize the data
// Serialize the data
tx
.
data
=
make
([]
string
,
len
(
data
))
tx
.
data
=
make
([]
string
,
len
(
data
))
...
@@ -73,16 +75,67 @@ func NewTransaction(to uint32, value uint32, data []string) *Transaction {
...
@@ -73,16 +75,67 @@ func NewTransaction(to uint32, value uint32, data []string) *Transaction {
func
(
tx
*
Transaction
)
MarshalRlp
()
[]
byte
{
func
(
tx
*
Transaction
)
MarshalRlp
()
[]
byte
{
// Prepare the transaction for serialization
// Prepare the transaction for serialization
preEnc
:=
[]
interface
{}{
preEnc
:=
[]
interface
{}{
"0"
,
// TODO
last
Tx
tx
.
lastTx
,
tx
.
sender
,
tx
.
sender
,
// XXX In the future there's no need to cast to string because they'll end up being big numbers (strings)
tx
.
recipient
,
Uitoa
(
tx
.
recipient
),
tx
.
value
,
Uitoa
(
tx
.
value
),
tx
.
fee
,
Uitoa
(
tx
.
fee
),
tx
.
data
,
tx
.
data
,
}
}
return
[]
byte
(
RlpEncode
(
preEnc
))
return
[]
byte
(
Encode
(
preEnc
))
}
func
(
tx
*
Transaction
)
UnmarshalRlp
(
data
[]
byte
)
{
t
,
_
:=
Decode
(
data
,
0
)
if
slice
,
ok
:=
t
.
([]
interface
{});
ok
{
if
lastTx
,
ok
:=
slice
[
0
]
.
([]
byte
);
ok
{
tx
.
lastTx
=
string
(
lastTx
)
}
if
sender
,
ok
:=
slice
[
1
]
.
([]
byte
);
ok
{
tx
.
sender
=
string
(
sender
)
}
if
recipient
,
ok
:=
slice
[
2
]
.
([]
byte
);
ok
{
tx
.
recipient
=
string
(
recipient
)
}
// If only I knew of a better way.
if
value
,
ok
:=
slice
[
3
]
.
(
uint8
);
ok
{
tx
.
value
=
uint32
(
value
)
}
if
value
,
ok
:=
slice
[
3
]
.
(
uint16
);
ok
{
tx
.
value
=
uint32
(
value
)
}
if
value
,
ok
:=
slice
[
3
]
.
(
uint32
);
ok
{
tx
.
value
=
uint32
(
value
)
}
if
value
,
ok
:=
slice
[
3
]
.
(
uint64
);
ok
{
tx
.
value
=
uint32
(
value
)
}
if
fee
,
ok
:=
slice
[
4
]
.
(
uint8
);
ok
{
tx
.
fee
=
uint32
(
fee
)
}
if
fee
,
ok
:=
slice
[
4
]
.
(
uint16
);
ok
{
tx
.
fee
=
uint32
(
fee
)
}
if
fee
,
ok
:=
slice
[
4
]
.
(
uint32
);
ok
{
tx
.
fee
=
uint32
(
fee
)
}
if
fee
,
ok
:=
slice
[
4
]
.
(
uint64
);
ok
{
tx
.
fee
=
uint32
(
fee
)
}
if
data
,
ok
:=
slice
[
5
]
.
([]
interface
{});
ok
{
tx
.
data
=
make
([]
string
,
len
(
data
))
for
i
,
d
:=
range
data
{
if
instr
,
ok
:=
d
.
([]
byte
);
ok
{
tx
.
data
[
i
]
=
string
(
instr
)
}
}
}
}
}
}
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