forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 7
XEth
Taylor Gerring edited this page Feb 4, 2015
·
3 revisions
NOTE: This documentation is out-of-date and in need of refresh against current codebase
General, easy to use, ethereum query interface. This API allows you to easily interface with ethereum's state and their respective objects, create transactions and directly evaluate contract code.
import "github.com/ethereum/go-ethereum/xeth"Be aware that all methods return something. Nil isn't ever returned unless explicitly specified.
-
XEth: Top level query interface -
World: world object through which you can query ethereum's state and objects. -
Config: config object through which you can query theConfigcontract if available. -
Object: object which functions as a proxy forStateObject. Returned byconfig
-
New(ethchain.EthManager) *XEth: instantiate a new ethpipe object.
-
World() *world: returns the world object through which you can query ethereum's state. -
Balance(address []byte) *Value: returns the balance of the givenaddress. -
Exists(address []byte) bool: returns whether an object with the givenaddressexists. -
Nonce(address []byte) *uint64: returns the the nonce of the givenaddress. -
Block(hash []byte) *Block: returns the given block byhash. -
Storage(address, storage []byte) *Value: returns the given object byaddress's value given by thestorageaddress. -
ToAddress(privateKey []byte) []byte: converts a private key to an ethereum address. -
Execute(address, data []byte, value, gas, price *Value) []byte: Simulates an evaluation of the object's code given by theaddressand returns the outcome. -
ExecuteObject(object *Object, data []byte, value, gas, price *Value) []byte: Similar to the above only takes an actualStateObjectinstead of an address. -
Transact(key *KeyPair, address []byte, value, gas, price *Value, data []byte) ([]byte, error): creates a new transaction using the givenkey.
-
State() *State: returns the current state of the ethereumworldobject. -
Get(addres []byte) *StateObject: returns the object given by theaddress. Returnsnilif no object associated with theaddresscan be found. Config() *config-
IsListening() bool: returns whether the client is listening for connections. -
IsMining() bool: returns whether the client is mining. -
Peers() *list.List: returns the current connected peers. -
Coinbase() *StateObject: TODO
-
Get(name string) object: returns the associated object given by thename. -
Exist() bool: returns whether the config object exist in ethereum's present state.
-
StorageString(str string) *Value: returns the storage value given by the key asstr(Note, right pads zero to length of 32). -
Storage(addr []byte): return the storage value given by the key asaddress.
import "github.com/ethereum/go-ethereum/xeth"
xeth := xeth.New(ethereum)
var addr, privy, recp, data []byte
var object *ethstate.StateObject
var key *ethcrypto.KeyPair
world := xeth.World()
world.Get(addr)
world.Coinbase()
world.IsMining()
world.IsListening()
world.State()
peers := world.Peers()
peers.Len()
// Shortcut functions
xeth.Balance(addr)
xeth.Nonce(addr)
xeth.Block(addr)
xeth.Storage(addr, addr)
xeth.ToAddress(privy)
// Doesn't change state
xeth.Execute(addr, nil, Val(0), Val(1000000), Val(10))
// Doesn't change state
xeth.ExecuteObject(object, nil, Val(0), Val(1000000), Val(10))
conf := world.Config()
namereg := conf.Get("NameReg")
namereg.Storage(addr)
var err error
// Transact
tx_hash, err = xeth.Transact(key, recp, ethutil.NewValue(0), ethutil.NewValue(0), ethutil.NewValue(0), nil)
if err != nil {
t.Error(err)
}
// Create
contract_addr, err = xeth.Transact(key, nil, ethutil.NewValue(0), ethutil.NewValue(0), ethutil.NewValue(0), data)
if err != nil {
t.Error(err)
}