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
43f1214f
Commit
43f1214f
authored
Apr 23, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored code
parent
b962779a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
13 deletions
+28
-13
library.go
ethereal/ui/library.go
+10
-13
compile.go
utils/compile.go
+18
-0
No files found.
ethereal/ui/library.go
View file @
43f1214f
...
...
@@ -43,8 +43,7 @@ func (lib *EthLib) CreateAndSetPrivKey() (string, string, string, string) {
return
mnemonicString
,
fmt
.
Sprintf
(
"%x"
,
pair
.
Address
()),
fmt
.
Sprintf
(
"%x"
,
prv
),
fmt
.
Sprintf
(
"%x"
,
pub
)
}
func
(
lib
*
EthLib
)
CreateTx
(
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
data
string
)
(
string
,
error
)
{
fmt
.
Println
(
"Create tx"
)
func
(
lib
*
EthLib
)
CreateTx
(
recipient
,
valueStr
,
gasStr
,
gasPriceStr
,
dataStr
string
)
(
string
,
error
)
{
var
hash
[]
byte
var
contractCreation
bool
if
len
(
recipient
)
==
0
{
...
...
@@ -64,26 +63,24 @@ func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, data strin
var
tx
*
ethchain
.
Transaction
// Compile and assemble the given data
if
contractCreation
{
mainInput
,
initInput
:=
ethutil
.
PreProcess
(
data
)
fmt
.
Println
(
"Precompile done"
)
fmt
.
Println
(
"main"
,
mainInput
)
mainScript
,
err
:=
utils
.
Compile
(
mainInput
)
if
err
!=
nil
{
return
""
,
err
}
fmt
.
Println
(
"init"
,
initInput
)
initScript
,
err
:=
utils
.
Compile
(
initInput
)
// Compile script
mainScript
,
initScript
,
err
:=
utils
.
CompileScript
(
dataStr
)
if
err
!=
nil
{
return
""
,
err
}
tx
=
ethchain
.
NewContractCreationTx
(
value
,
gas
,
gasPrice
,
mainScript
,
initScript
)
}
else
{
tx
=
ethchain
.
NewTransactionMessage
(
hash
,
value
,
gas
,
gasPrice
,
nil
)
lines
:=
strings
.
Split
(
dataStr
,
"
\n
"
)
var
data
[]
byte
for
_
,
line
:=
range
lines
{
data
=
append
(
data
,
ethutil
.
BigToBytes
(
ethutil
.
Big
(
line
),
256
)
...
)
}
tx
=
ethchain
.
NewTransactionMessage
(
hash
,
value
,
gas
,
gasPrice
,
data
)
}
acc
:=
lib
.
stateManager
.
GetAddrState
(
keyPair
.
Address
())
tx
.
Nonce
=
acc
.
Nonce
//acc.Nonce++
tx
.
Sign
(
keyPair
.
PrivateKey
)
lib
.
txPool
.
QueueTransaction
(
tx
)
...
...
utils/compile.go
View file @
43f1214f
...
...
@@ -22,3 +22,21 @@ func Compile(script string) ([]byte, error) {
return
ethutil
.
Assemble
(
asm
...
),
nil
}
func
CompileScript
(
script
string
)
([]
byte
,
[]
byte
,
error
)
{
// Preprocess
mainInput
,
initInput
:=
ethutil
.
PreProcess
(
script
)
// Compile main script
mainScript
,
err
:=
Compile
(
mainInput
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
// Compile init script
initScript
,
err
:=
Compile
(
initInput
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
return
mainScript
,
initScript
,
nil
}
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