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
4f20e8f6
Commit
4f20e8f6
authored
May 02, 2014
by
Maran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented first few methods via public api
parent
69d83b1d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
28 deletions
+37
-28
ethereum.go
ethereum.go
+2
-3
packages.go
etherpc/packages.go
+23
-16
server.go
etherpc/server.go
+5
-2
pub.go
ethpub/pub.go
+1
-1
types.go
ethpub/types.go
+6
-6
No files found.
ethereum.go
View file @
4f20e8f6
...
@@ -4,7 +4,6 @@ import (
...
@@ -4,7 +4,6 @@ import (
"container/list"
"container/list"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/etherpc"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
"github.com/ethereum/eth-go/ethwire"
"io/ioutil"
"io/ioutil"
...
@@ -64,7 +63,7 @@ type Ethereum struct {
...
@@ -64,7 +63,7 @@ type Ethereum struct {
reactor
*
ethutil
.
ReactorEngine
reactor
*
ethutil
.
ReactorEngine
RpcServer
*
etherpc
.
JsonRpcServer
// TODO: This no worky:
RpcServer *etherpc.JsonRpcServer
}
}
func
New
(
caps
Caps
,
usePnp
bool
)
(
*
Ethereum
,
error
)
{
func
New
(
caps
Caps
,
usePnp
bool
)
(
*
Ethereum
,
error
)
{
...
@@ -341,7 +340,7 @@ func (s *Ethereum) Stop() {
...
@@ -341,7 +340,7 @@ func (s *Ethereum) Stop() {
s
.
txPool
.
Stop
()
s
.
txPool
.
Stop
()
s
.
stateManager
.
Stop
()
s
.
stateManager
.
Stop
()
s
.
RpcServer
.
Stop
()
// TODO: THIS NO WORKY:
s.RpcServer.Stop()
close
(
s
.
shutdownChan
)
close
(
s
.
shutdownChan
)
}
}
...
...
etherpc/packages.go
View file @
4f20e8f6
...
@@ -3,18 +3,20 @@ package etherpc
...
@@ -3,18 +3,20 @@ package etherpc
import
(
import
(
"encoding/json"
"encoding/json"
"errors"
"errors"
"math/big"
"github.com/ethereum/eth-go/ethpub"
_
"log"
)
)
type
MainPackage
struct
{}
type
MainPackage
struct
{
ethp
*
ethpub
.
PEthereum
}
type
JsonArgs
interface
{
type
JsonArgs
interface
{
requirements
()
error
requirements
()
error
}
}
type
BlockResponse
struct
{
type
BlockResponse
struct
{
Name
string
JsonResponse
Id
int
}
}
type
GetBlockArgs
struct
{
type
GetBlockArgs
struct
{
BlockNumber
int
BlockNumber
int
...
@@ -63,22 +65,23 @@ func (b *GetBlockArgs) requirements() error {
...
@@ -63,22 +65,23 @@ func (b *GetBlockArgs) requirements() error {
return
nil
return
nil
}
}
func
(
p
*
MainPackage
)
GetBlock
(
args
*
GetBlockArgs
,
reply
*
BlockResponse
)
error
{
func
(
p
*
MainPackage
)
GetBlock
(
args
*
GetBlockArgs
,
reply
*
string
)
error
{
err
:=
args
.
requirements
()
err
:=
args
.
requirements
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
// Do something
// Do something
block
:=
p
.
ethp
.
GetBlock
(
args
.
Hash
)
*
reply
=
NewSuccessRes
(
block
)
return
nil
return
nil
}
}
type
NewTxArgs
struct
{
type
NewTxArgs
struct
{
Sec
string
Sec
string
Recipient
string
Recipient
string
Value
*
big
.
Int
Value
string
Gas
*
big
.
Int
Gas
string
GasPrice
*
big
.
Int
GasPrice
string
Init
string
Init
string
Body
string
Body
string
}
}
...
@@ -90,26 +93,26 @@ func (a *NewTxArgs) requirements() error {
...
@@ -90,26 +93,26 @@ func (a *NewTxArgs) requirements() error {
if
a
.
Recipient
==
""
{
if
a
.
Recipient
==
""
{
return
NewErrorResponse
(
"Transact requires a 'recipient' address as argument"
)
return
NewErrorResponse
(
"Transact requires a 'recipient' address as argument"
)
}
}
if
a
.
Value
==
nil
{
if
a
.
Value
==
""
{
return
NewErrorResponse
(
"Transact requires a 'value' as argument"
)
return
NewErrorResponse
(
"Transact requires a 'value' as argument"
)
}
}
if
a
.
Gas
==
nil
{
if
a
.
Gas
==
""
{
return
NewErrorResponse
(
"Transact requires a 'gas' value as argument"
)
return
NewErrorResponse
(
"Transact requires a 'gas' value as argument"
)
}
}
if
a
.
GasPrice
==
nil
{
if
a
.
GasPrice
==
""
{
return
NewErrorResponse
(
"Transact requires a 'gasprice' value as argument"
)
return
NewErrorResponse
(
"Transact requires a 'gasprice' value as argument"
)
}
}
return
nil
return
nil
}
}
func
(
a
*
NewTxArgs
)
requirementsContract
()
error
{
func
(
a
*
NewTxArgs
)
requirementsContract
()
error
{
if
a
.
Value
==
nil
{
if
a
.
Value
==
""
{
return
NewErrorResponse
(
"Create requires a 'value' as argument"
)
return
NewErrorResponse
(
"Create requires a 'value' as argument"
)
}
}
if
a
.
Gas
==
nil
{
if
a
.
Gas
==
""
{
return
NewErrorResponse
(
"Create requires a 'gas' value as argument"
)
return
NewErrorResponse
(
"Create requires a 'gas' value as argument"
)
}
}
if
a
.
GasPrice
==
nil
{
if
a
.
GasPrice
==
""
{
return
NewErrorResponse
(
"Create requires a 'gasprice' value as argument"
)
return
NewErrorResponse
(
"Create requires a 'gasprice' value as argument"
)
}
}
if
a
.
Init
==
""
{
if
a
.
Init
==
""
{
...
@@ -121,11 +124,13 @@ func (a *NewTxArgs) requirementsContract() error {
...
@@ -121,11 +124,13 @@ func (a *NewTxArgs) requirementsContract() error {
return
nil
return
nil
}
}
func
(
p
*
MainPackage
)
Transact
(
args
*
NewTxArgs
,
reply
*
TxResponse
)
error
{
func
(
p
*
MainPackage
)
Transact
(
args
*
NewTxArgs
,
reply
*
string
)
error
{
err
:=
args
.
requirements
()
err
:=
args
.
requirements
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
result
,
_
:=
p
.
ethp
.
Transact
(
p
.
ethp
.
GetKey
()
.
PrivateKey
,
args
.
Recipient
,
args
.
Value
,
args
.
Gas
,
args
.
GasPrice
,
args
.
Body
)
*
reply
=
NewSuccessRes
(
result
)
return
nil
return
nil
}
}
...
@@ -134,6 +139,8 @@ func (p *MainPackage) Create(args *NewTxArgs, reply *string) error {
...
@@ -134,6 +139,8 @@ func (p *MainPackage) Create(args *NewTxArgs, reply *string) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
result
,
_
:=
p
.
ethp
.
Create
(
p
.
ethp
.
GetKey
()
.
PrivateKey
,
args
.
Value
,
args
.
Gas
,
args
.
GasPrice
,
args
.
Init
,
args
.
Body
)
*
reply
=
NewSuccessRes
(
result
)
return
nil
return
nil
}
}
...
...
etherpc/server.go
View file @
4f20e8f6
package
etherpc
package
etherpc
import
(
import
(
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
"net"
"net"
"net/rpc"
"net/rpc"
...
@@ -10,6 +11,7 @@ import (
...
@@ -10,6 +11,7 @@ import (
type
JsonRpcServer
struct
{
type
JsonRpcServer
struct
{
quit
chan
bool
quit
chan
bool
listener
net
.
Listener
listener
net
.
Listener
ethp
*
ethpub
.
PEthereum
}
}
func
(
s
*
JsonRpcServer
)
exitHandler
()
{
func
(
s
*
JsonRpcServer
)
exitHandler
()
{
...
@@ -32,7 +34,7 @@ func (s *JsonRpcServer) Stop() {
...
@@ -32,7 +34,7 @@ func (s *JsonRpcServer) Stop() {
func
(
s
*
JsonRpcServer
)
Start
()
{
func
(
s
*
JsonRpcServer
)
Start
()
{
ethutil
.
Config
.
Log
.
Infoln
(
"[JSON] Starting JSON-RPC server"
)
ethutil
.
Config
.
Log
.
Infoln
(
"[JSON] Starting JSON-RPC server"
)
go
s
.
exitHandler
()
go
s
.
exitHandler
()
rpc
.
Register
(
new
(
MainPackage
)
)
rpc
.
Register
(
&
MainPackage
{
ethp
:
s
.
ethp
}
)
rpc
.
HandleHTTP
()
rpc
.
HandleHTTP
()
for
{
for
{
...
@@ -46,7 +48,7 @@ func (s *JsonRpcServer) Start() {
...
@@ -46,7 +48,7 @@ func (s *JsonRpcServer) Start() {
}
}
}
}
func
NewJsonRpcServer
()
*
JsonRpcServer
{
func
NewJsonRpcServer
(
ethp
*
ethpub
.
PEthereum
)
*
JsonRpcServer
{
l
,
err
:=
net
.
Listen
(
"tcp"
,
":30304"
)
l
,
err
:=
net
.
Listen
(
"tcp"
,
":30304"
)
if
err
!=
nil
{
if
err
!=
nil
{
ethutil
.
Config
.
Log
.
Infoln
(
"Error starting JSON-RPC"
)
ethutil
.
Config
.
Log
.
Infoln
(
"Error starting JSON-RPC"
)
...
@@ -55,5 +57,6 @@ func NewJsonRpcServer() *JsonRpcServer {
...
@@ -55,5 +57,6 @@ func NewJsonRpcServer() *JsonRpcServer {
return
&
JsonRpcServer
{
return
&
JsonRpcServer
{
listener
:
l
,
listener
:
l
,
quit
:
make
(
chan
bool
),
quit
:
make
(
chan
bool
),
ethp
:
ethp
,
}
}
}
}
ethpub/pub.go
View file @
4f20e8f6
...
@@ -87,7 +87,7 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in
...
@@ -87,7 +87,7 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, in
tx
=
ethchain
.
NewContractCreationTx
(
value
,
gas
,
gasPrice
,
mainScript
,
initScript
)
tx
=
ethchain
.
NewContractCreationTx
(
value
,
gas
,
gasPrice
,
mainScript
,
initScript
)
}
else
{
}
else
{
// Just in case it was submitted as a 0x prefixed string
// Just in case it was submitted as a 0x prefixed string
if
initStr
[
0
:
2
]
==
"0x"
{
if
len
(
initStr
)
>
0
&&
initStr
[
0
:
2
]
==
"0x"
{
initStr
=
initStr
[
2
:
len
(
initStr
)]
initStr
=
initStr
[
2
:
len
(
initStr
)]
}
}
tx
=
ethchain
.
NewTransactionMessage
(
hash
,
value
,
gas
,
gasPrice
,
ethutil
.
FromHex
(
initStr
))
tx
=
ethchain
.
NewTransactionMessage
(
hash
,
value
,
gas
,
gasPrice
,
ethutil
.
FromHex
(
initStr
))
...
...
ethpub/types.go
View file @
4f20e8f6
...
@@ -8,8 +8,8 @@ import (
...
@@ -8,8 +8,8 @@ import (
// Block interface exposed to QML
// Block interface exposed to QML
type
PBlock
struct
{
type
PBlock
struct
{
Number
int
Number
int
`json:"number"`
Hash
string
Hash
string
`json:"hash"`
}
}
// Creates a new QML Block from a chain block
// Creates a new QML Block from a chain block
...
@@ -44,10 +44,10 @@ func NewPKey(key *ethchain.KeyPair) *PKey {
...
@@ -44,10 +44,10 @@ func NewPKey(key *ethchain.KeyPair) *PKey {
}
}
type
PReceipt
struct
{
type
PReceipt
struct
{
CreatedContract
bool
CreatedContract
bool
`json:"createdContract"`
Address
string
Address
string
`json:"address"`
Hash
string
Hash
string
`json:"hash"`
Sender
string
Sender
string
`json:"sender"`
}
}
func
NewPReciept
(
contractCreation
bool
,
creationAddress
,
hash
,
address
[]
byte
)
*
PReceipt
{
func
NewPReciept
(
contractCreation
bool
,
creationAddress
,
hash
,
address
[]
byte
)
*
PReceipt
{
...
...
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