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
720521ed
Commit
720521ed
authored
Apr 09, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed how txs define their data & added init field
parent
e09f0a5f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
94 deletions
+25
-94
transaction.go
ethchain/transaction.go
+25
-41
transaction_test.go
ethchain/transaction_test.go
+0
-53
No files found.
ethchain/transaction.go
View file @
720521ed
...
@@ -14,7 +14,8 @@ type Transaction struct {
...
@@ -14,7 +14,8 @@ type Transaction struct {
Value
*
big
.
Int
Value
*
big
.
Int
Gas
*
big
.
Int
Gas
*
big
.
Int
Gasprice
*
big
.
Int
Gasprice
*
big
.
Int
Data
[]
string
Data
[]
byte
Init
[]
byte
v
byte
v
byte
r
,
s
[]
byte
r
,
s
[]
byte
...
@@ -22,11 +23,11 @@ type Transaction struct {
...
@@ -22,11 +23,11 @@ type Transaction struct {
contractCreation
bool
contractCreation
bool
}
}
func
NewContractCreationTx
(
value
,
gasprice
*
big
.
Int
,
data
[]
string
)
*
Transaction
{
func
NewContractCreationTx
(
value
,
gasprice
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
return
&
Transaction
{
Value
:
value
,
Gasprice
:
gasprice
,
Data
:
data
,
contractCreation
:
true
}
return
&
Transaction
{
Value
:
value
,
Gasprice
:
gasprice
,
Data
:
data
,
contractCreation
:
true
}
}
}
func
NewTransactionMessage
(
to
[]
byte
,
value
,
gasprice
,
gas
*
big
.
Int
,
data
[]
string
)
*
Transaction
{
func
NewTransactionMessage
(
to
[]
byte
,
value
,
gasprice
,
gas
*
big
.
Int
,
data
[]
byte
)
*
Transaction
{
return
&
Transaction
{
Recipient
:
to
,
Value
:
value
,
Gasprice
:
gasprice
,
Gas
:
gas
,
Data
:
data
}
return
&
Transaction
{
Recipient
:
to
,
Value
:
value
,
Gasprice
:
gasprice
,
Gas
:
gas
,
Data
:
data
}
}
}
...
@@ -45,19 +46,12 @@ func NewTransactionFromValue(val *ethutil.Value) *Transaction {
...
@@ -45,19 +46,12 @@ func NewTransactionFromValue(val *ethutil.Value) *Transaction {
}
}
func
(
tx
*
Transaction
)
Hash
()
[]
byte
{
func
(
tx
*
Transaction
)
Hash
()
[]
byte
{
data
:=
make
([]
interface
{},
len
(
tx
.
Data
))
data
:=
[]
interface
{}{
tx
.
Nonce
,
tx
.
Value
,
tx
.
Gasprice
,
tx
.
Gas
,
tx
.
Recipient
,
string
(
tx
.
Data
)}
for
i
,
val
:=
range
tx
.
Data
{
if
tx
.
contractCreation
{
data
[
i
]
=
val
data
=
append
(
data
,
string
(
tx
.
Init
))
}
}
preEnc
:=
[]
interface
{}{
return
ethutil
.
Sha3Bin
(
ethutil
.
NewValue
(
data
)
.
Encode
())
tx
.
Nonce
,
tx
.
Recipient
,
tx
.
Value
,
data
,
}
return
ethutil
.
Sha3Bin
(
ethutil
.
Encode
(
preEnc
))
}
}
func
(
tx
*
Transaction
)
IsContract
()
bool
{
func
(
tx
*
Transaction
)
IsContract
()
bool
{
...
@@ -110,15 +104,17 @@ func (tx *Transaction) Sign(privk []byte) error {
...
@@ -110,15 +104,17 @@ func (tx *Transaction) Sign(privk []byte) error {
return
nil
return
nil
}
}
// [ NONCE, VALUE, GASPRICE, GAS, TO, DATA, V, R, S ]
// [ NONCE, VALUE, GASPRICE, GAS, 0, CODE, INIT, V, R, S ]
func
(
tx
*
Transaction
)
RlpData
()
interface
{}
{
func
(
tx
*
Transaction
)
RlpData
()
interface
{}
{
data
:=
[]
interface
{}{
tx
.
Nonce
,
tx
.
Value
,
tx
.
Gasprice
}
data
:=
[]
interface
{}{
tx
.
Nonce
,
tx
.
Value
,
tx
.
Gasprice
,
tx
.
Gas
,
tx
.
Recipient
,
tx
.
Data
}
if
!
tx
.
contractCreation
{
if
tx
.
contractCreation
{
data
=
append
(
data
,
tx
.
Recipient
,
tx
.
Gas
)
data
=
append
(
data
,
tx
.
Init
)
}
}
d
:=
ethutil
.
NewSliceValue
(
tx
.
Data
)
.
Slice
()
//
d := ethutil.NewSliceValue(tx.Data).Slice()
return
append
(
data
,
d
,
tx
.
v
,
tx
.
r
,
tx
.
s
)
return
append
(
data
,
tx
.
v
,
tx
.
r
,
tx
.
s
)
}
}
func
(
tx
*
Transaction
)
RlpValue
()
*
ethutil
.
Value
{
func
(
tx
*
Transaction
)
RlpValue
()
*
ethutil
.
Value
{
...
@@ -137,31 +133,19 @@ func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value) {
...
@@ -137,31 +133,19 @@ func (tx *Transaction) RlpValueDecode(decoder *ethutil.Value) {
tx
.
Nonce
=
decoder
.
Get
(
0
)
.
Uint
()
tx
.
Nonce
=
decoder
.
Get
(
0
)
.
Uint
()
tx
.
Value
=
decoder
.
Get
(
1
)
.
BigInt
()
tx
.
Value
=
decoder
.
Get
(
1
)
.
BigInt
()
tx
.
Gasprice
=
decoder
.
Get
(
2
)
.
BigInt
()
tx
.
Gasprice
=
decoder
.
Get
(
2
)
.
BigInt
()
tx
.
Gas
=
decoder
.
Get
(
3
)
.
BigInt
()
tx
.
Recipient
=
decoder
.
Get
(
4
)
.
Bytes
()
tx
.
Data
=
decoder
.
Get
(
5
)
.
Bytes
()
// If the 4th item is a list(slice) this tx
// If the list is of length 10 it's a contract creation tx
// is a contract creation tx
if
decoder
.
Len
()
==
10
{
if
decoder
.
Get
(
3
)
.
IsList
()
{
d
:=
decoder
.
Get
(
3
)
tx
.
Data
=
make
([]
string
,
d
.
Len
())
for
i
:=
0
;
i
<
d
.
Len
();
i
++
{
tx
.
Data
[
i
]
=
d
.
Get
(
i
)
.
Str
()
}
tx
.
v
=
byte
(
decoder
.
Get
(
4
)
.
Uint
())
tx
.
r
=
decoder
.
Get
(
5
)
.
Bytes
()
tx
.
s
=
decoder
.
Get
(
6
)
.
Bytes
()
tx
.
contractCreation
=
true
tx
.
contractCreation
=
true
}
else
{
tx
.
Init
=
decoder
.
Get
(
6
)
.
Bytes
()
tx
.
Recipient
=
decoder
.
Get
(
3
)
.
Bytes
()
tx
.
Gas
=
decoder
.
Get
(
4
)
.
BigInt
()
d
:=
decoder
.
Get
(
5
)
tx
.
Data
=
make
([]
string
,
d
.
Len
())
for
i
:=
0
;
i
<
d
.
Len
();
i
++
{
tx
.
Data
[
i
]
=
d
.
Get
(
i
)
.
Str
()
}
tx
.
v
=
byte
(
decoder
.
Get
(
7
)
.
Uint
())
tx
.
r
=
decoder
.
Get
(
8
)
.
Bytes
()
tx
.
s
=
decoder
.
Get
(
9
)
.
Bytes
()
}
else
{
tx
.
v
=
byte
(
decoder
.
Get
(
6
)
.
Uint
())
tx
.
v
=
byte
(
decoder
.
Get
(
6
)
.
Uint
())
tx
.
r
=
decoder
.
Get
(
7
)
.
Bytes
()
tx
.
r
=
decoder
.
Get
(
7
)
.
Bytes
()
tx
.
s
=
decoder
.
Get
(
8
)
.
Bytes
()
tx
.
s
=
decoder
.
Get
(
8
)
.
Bytes
()
...
...
ethchain/transaction_test.go
View file @
720521ed
package
ethchain
package
ethchain
import
(
"encoding/hex"
"math/big"
"testing"
)
func
TestAddressRetrieval
(
t
*
testing
.
T
)
{
// TODO
// 88f9b82462f6c4bf4a0fb15e5c3971559a316e7f
key
,
_
:=
hex
.
DecodeString
(
"3ecb44df2159c26e0f995712d4f39b6f6e499b40749b1cf1246c37f9516cb6a4"
)
tx
:=
&
Transaction
{
Nonce
:
0
,
Recipient
:
ZeroHash160
,
Value
:
big
.
NewInt
(
0
),
Data
:
nil
,
}
//fmt.Printf("rlp %x\n", tx.RlpEncode())
//fmt.Printf("sha rlp %x\n", tx.Hash())
tx
.
Sign
(
key
)
//fmt.Printf("hex tx key %x\n", tx.PublicKey())
//fmt.Printf("seder %x\n", tx.Sender())
}
func
TestAddressRetrieval2
(
t
*
testing
.
T
)
{
// TODO
// 88f9b82462f6c4bf4a0fb15e5c3971559a316e7f
key
,
_
:=
hex
.
DecodeString
(
"3ecb44df2159c26e0f995712d4f39b6f6e499b40749b1cf1246c37f9516cb6a4"
)
addr
,
_
:=
hex
.
DecodeString
(
"944400f4b88ac9589a0f17ed4671da26bddb668b"
)
tx
:=
&
Transaction
{
Nonce
:
0
,
Recipient
:
addr
,
Value
:
big
.
NewInt
(
1000
),
Data
:
nil
,
}
tx
.
Sign
(
key
)
//data, _ := hex.DecodeString("f85d8094944400f4b88ac9589a0f17ed4671da26bddb668b8203e8c01ca0363b2a410de00bc89be40f468d16e70e543b72191fbd8a684a7c5bef51dc451fa02d8ecf40b68f9c64ed623f6ee24c9c878943b812e1e76bd73ccb2bfef65579e7")
//tx := NewTransactionFromData(data)
/*
fmt.Println(tx.RlpValue())
fmt.Printf("rlp %x\n", tx.RlpEncode())
fmt.Printf("sha rlp %x\n", tx.Hash())
//tx.Sign(key)
fmt.Printf("hex tx key %x\n", tx.PublicKey())
fmt.Printf("seder %x\n", tx.Sender())
*/
}
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