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
8e7daec8
Commit
8e7daec8
authored
Feb 19, 2014
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Added fees and debugging
parent
b3da104e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ethchain/block_manager.go
+42
-12
42 additions, 12 deletions
ethchain/block_manager.go
with
42 additions
and
12 deletions
ethchain/block_manager.go
+
42
−
12
View file @
8e7daec8
...
@@ -301,12 +301,12 @@ func (bm *BlockManager) ProcessContract(tx *Transaction, block *Block) {
...
@@ -301,12 +301,12 @@ func (bm *BlockManager) ProcessContract(tx *Transaction, block *Block) {
// Contract evaluation is done here.
// Contract evaluation is done here.
func
(
bm
*
BlockManager
)
ProcContract
(
tx
*
Transaction
,
block
*
Block
,
cb
TxCallback
)
{
func
(
bm
*
BlockManager
)
ProcContract
(
tx
*
Transaction
,
block
*
Block
,
cb
TxCallback
)
{
addr
:=
tx
.
Hash
()[
12
:
]
// Instruction pointer
// Instruction pointer
pc
:=
0
pc
:=
0
blockInfo
:=
bm
.
bc
.
BlockInfo
(
block
)
blockInfo
:=
bm
.
bc
.
BlockInfo
(
block
)
contract
:=
block
.
GetContract
(
tx
.
Hash
()
)
contract
:=
block
.
GetContract
(
addr
)
if
contract
==
nil
{
if
contract
==
nil
{
fmt
.
Println
(
"Contract not found"
)
fmt
.
Println
(
"Contract not found"
)
...
@@ -318,8 +318,12 @@ func (bm *BlockManager) ProcContract(tx *Transaction, block *Block, cb TxCallbac
...
@@ -318,8 +318,12 @@ func (bm *BlockManager) ProcContract(tx *Transaction, block *Block, cb TxCallbac
if
ethutil
.
Config
.
Debug
{
if
ethutil
.
Config
.
Debug
{
fmt
.
Printf
(
"# op
\n
"
)
fmt
.
Printf
(
"# op
\n
"
)
}
}
stepcount
:=
0
totalFee
:=
new
(
big
.
Int
)
out
:
out
:
for
{
for
{
stepcount
++
// The base big int for all calculations. Use this for any results.
// The base big int for all calculations. Use this for any results.
base
:=
new
(
big
.
Int
)
base
:=
new
(
big
.
Int
)
// XXX Should Instr return big int slice instead of string slice?
// XXX Should Instr return big int slice instead of string slice?
...
@@ -331,12 +335,40 @@ out:
...
@@ -331,12 +335,40 @@ out:
o
:=
v
.
Uint
()
o
:=
v
.
Uint
()
op
:=
OpCode
(
o
)
op
:=
OpCode
(
o
)
var
fee
*
big
.
Int
=
new
(
big
.
Int
)
if
stepcount
>
16
{
fee
.
Add
(
fee
,
StepFee
)
}
// Calculate the fees
switch
op
{
/*
FIXME (testnet requires no funds yet)
case oSSTORE:
fee.Add(fee, StoreFee)
case oSLOAD:
fee.Add(fee, StoreFee)
*/
case
oEXTRO
,
oBALANCE
:
fee
.
Add
(
fee
,
ExtroFee
)
case
oSHA256
,
oRIPEMD160
,
oECMUL
,
oECADD
,
oECSIGN
,
oECRECOVER
,
oECVALID
:
fee
.
Add
(
fee
,
CryptoFee
)
case
oMKTX
:
fee
.
Add
(
fee
,
ContractFee
)
}
if
contract
.
Amount
.
Cmp
(
fee
)
<
0
{
break
}
// Add the fee to the total fee. It's subtracted when we're done looping
totalFee
.
Add
(
totalFee
,
fee
)
if
!
cb
(
0
)
{
if
!
cb
(
0
)
{
break
break
}
}
if
ethutil
.
Config
.
Debug
{
if
ethutil
.
Config
.
Debug
{
fmt
.
Printf
(
"%-3d %-4s
\n
"
,
pc
,
op
.
String
())
fmt
.
Printf
(
"%-3d %-4s"
,
pc
,
op
.
String
())
}
}
switch
op
{
switch
op
{
...
@@ -453,10 +485,6 @@ out:
...
@@ -453,10 +485,6 @@ out:
}
else
{
}
else
{
bm
.
stack
.
Push
(
ethutil
.
BigFalse
)
bm
.
stack
.
Push
(
ethutil
.
BigFalse
)
}
}
// Please note that the following code contains some
// ugly string casting. This will have to change to big
// ints. TODO :)
case
oMYADDRESS
:
case
oMYADDRESS
:
bm
.
stack
.
Push
(
ethutil
.
BigD
(
tx
.
Hash
()))
bm
.
stack
.
Push
(
ethutil
.
BigD
(
tx
.
Hash
()))
case
oTXSENDER
:
case
oTXSENDER
:
...
@@ -579,11 +607,10 @@ out:
...
@@ -579,11 +607,10 @@ out:
}
}
case
oSSTORE
:
case
oSSTORE
:
// Store Y at index X
// Store Y at index X
x
,
y
:=
bm
.
stack
.
Popn
()
y
,
x
:=
bm
.
stack
.
Popn
()
idx
:=
ethutil
.
BigToBytes
(
x
,
256
)
idx
:=
ethutil
.
BigToBytes
(
x
,
256
)
val
:=
ethutil
.
NewValue
(
y
)
fmt
.
Printf
(
" => %x (%v) @ %v"
,
y
.
Bytes
(),
y
,
ethutil
.
BigD
(
idx
))
//fmt.Printf("STORING VALUE: %v @ %v\n", val.BigInt(), ethutil.BigD(idx))
contract
.
State
()
.
Update
(
string
(
idx
),
string
(
y
.
Bytes
()))
contract
.
State
()
.
Update
(
string
(
idx
),
string
(
val
.
Encode
()))
case
oJMP
:
case
oJMP
:
x
:=
int
(
bm
.
stack
.
Pop
()
.
Uint64
())
x
:=
int
(
bm
.
stack
.
Pop
()
.
Uint64
())
// Set pc to x - 1 (minus one so the incrementing at the end won't effect it)
// Set pc to x - 1 (minus one so the incrementing at the end won't effect it)
...
@@ -628,9 +655,12 @@ out:
...
@@ -628,9 +655,12 @@ out:
default
:
default
:
fmt
.
Println
(
"Invalid OPCODE"
,
op
)
fmt
.
Println
(
"Invalid OPCODE"
,
op
)
}
}
//bm.stack.Print()
fmt
.
Println
(
""
)
bm
.
stack
.
Print
()
pc
++
pc
++
}
}
block
.
UpdateContract
(
addr
,
contract
)
}
}
// Returns an address from the specified contract's address
// Returns an address from the specified contract's address
...
...
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