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
e91ab84d
Commit
e91ab84d
authored
Mar 17, 2015
by
Felix Lange
Browse files
Options
Downloads
Patches
Plain Diff
core/types: don't use Address zero value for invalid addresses
parent
d5de6489
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
core/types/transaction.go
+34
-25
34 additions, 25 deletions
core/types/transaction.go
core/types/transaction_test.go
+3
-2
3 additions, 2 deletions
core/types/transaction_test.go
with
37 additions
and
27 deletions
core/types/transaction.go
+
34
−
25
View file @
e91ab84d
...
...
@@ -2,6 +2,7 @@ package types
import
(
"bytes"
"errors"
"fmt"
"io"
"math/big"
...
...
@@ -21,19 +22,19 @@ type Transaction struct {
AccountNonce
uint64
Price
*
big
.
Int
GasLimit
*
big
.
Int
Recipient
common
.
Address
Recipient
*
common
.
Address
// nil means contract creation
Amount
*
big
.
Int
Payload
[]
byte
V
byte
R
,
S
[]
byte
}
func
NewContractCreationTx
(
amount
,
gas
Amount
,
p
rice
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
return
New
Transaction
Message
(
common
.
Address
{},
amount
,
gasAmount
,
price
,
data
)
func
NewContractCreationTx
(
amount
,
gas
Limit
,
gasP
rice
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
return
&
Transaction
{
Recipient
:
nil
,
Amount
:
amount
,
GasLimit
:
gasLimit
,
Price
:
gasPrice
,
Payload
:
data
}
}
func
NewTransactionMessage
(
to
common
.
Address
,
amount
,
gasAmount
,
p
rice
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
return
&
Transaction
{
Recipient
:
to
,
Amount
:
amount
,
Price
:
price
,
GasLimit
:
gasAmount
,
Payload
:
data
}
func
NewTransactionMessage
(
to
common
.
Address
,
amount
,
gasAmount
,
gasP
rice
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
return
&
Transaction
{
Recipient
:
&
to
,
Amount
:
amount
,
GasLimit
:
gasAmount
,
Price
:
gasPrice
,
Payload
:
data
}
}
func
NewTransactionFromBytes
(
data
[]
byte
)
*
Transaction
{
...
...
@@ -73,12 +74,21 @@ func (self *Transaction) SetNonce(AccountNonce uint64) {
self
.
AccountNonce
=
AccountNonce
}
func
(
self
*
Transaction
)
From
()
common
.
Address
{
return
self
.
sender
()
func
(
self
*
Transaction
)
From
()
(
common
.
Address
,
error
)
{
pubkey
:=
self
.
PublicKey
()
if
len
(
pubkey
)
==
0
||
pubkey
[
0
]
!=
4
{
return
common
.
Address
{},
errors
.
New
(
"invalid public key"
)
}
var
addr
common
.
Address
copy
(
addr
[
:
],
crypto
.
Sha3
(
pubkey
[
1
:
]))
return
addr
,
nil
}
func
(
self
*
Transaction
)
To
()
common
.
Address
{
return
self
.
Recipient
// To returns the recipient of the transaction.
// If transaction is a contract creation (with no recipient address)
// To returns nil.
func
(
tx
*
Transaction
)
To
()
*
common
.
Address
{
return
tx
.
Recipient
}
func
(
tx
*
Transaction
)
Curve
()
(
v
byte
,
r
[]
byte
,
s
[]
byte
)
{
...
...
@@ -105,18 +115,6 @@ func (tx *Transaction) PublicKey() []byte {
return
pubkey
}
func
(
tx
*
Transaction
)
sender
()
(
a
common
.
Address
)
{
pubkey
:=
tx
.
PublicKey
()
// Validate the returned key.
// Return nil if public key isn't in full format
if
len
(
pubkey
)
==
0
||
pubkey
[
0
]
!=
4
{
return
a
}
copy
(
a
[
:
],
crypto
.
Sha3
(
pubkey
[
1
:
]))
return
a
}
func
(
tx
*
Transaction
)
SetSignatureValues
(
sig
[]
byte
)
error
{
tx
.
R
=
sig
[
:
32
]
tx
.
S
=
sig
[
32
:
64
]
...
...
@@ -149,11 +147,22 @@ func (tx *Transaction) RlpEncode() []byte {
}
func
(
tx
*
Transaction
)
String
()
string
{
var
from
,
to
string
if
f
,
err
:=
tx
.
From
();
err
!=
nil
{
from
=
"[invalid sender]"
}
else
{
from
=
fmt
.
Sprintf
(
"%x"
,
f
[
:
])
}
if
t
:=
tx
.
To
();
t
==
nil
{
to
=
"[contract creation]"
}
else
{
to
=
fmt
.
Sprintf
(
"%x"
,
t
[
:
])
}
return
fmt
.
Sprintf
(
`
TX(%x)
Contract: %v
From: %
x
To: %
x
From: %
s
To: %
s
Nonce: %v
GasPrice: %v
GasLimit %v
...
...
@@ -166,8 +175,8 @@ func (tx *Transaction) String() string {
`
,
tx
.
Hash
(),
len
(
tx
.
Recipient
)
==
0
,
tx
.
F
rom
()
,
t
x
.
To
()
,
f
rom
,
t
o
,
tx
.
AccountNonce
,
tx
.
Price
,
tx
.
GasLimit
,
...
...
This diff is collapsed.
Click to expand it.
core/types/transaction_test.go
+
3
−
2
View file @
e91ab84d
...
...
@@ -19,8 +19,9 @@ var (
nil
,
)
rightvrsRecipient
=
common
.
HexToAddress
(
"b94f5374fce5edbc8e2a8697c15331677e6ebf0b"
)
rightvrsTx
=
&
Transaction
{
Recipient
:
common
.
HexToAddress
(
"b94f5374fce5edbc8e2a8697c15331677e6ebf0b"
)
,
Recipient
:
&
rightvrsRecipient
,
AccountNonce
:
3
,
Price
:
big
.
NewInt
(
1
),
GasLimit
:
big
.
NewInt
(
2000
),
...
...
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