XEth - expanse-org/go-expanse GitHub Wiki
eXtended Ethereum API
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.
Objects
XEth: Top level query interfaceWorld: 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
Functions
New(ethchain.EthManager) *XEth: instantiate a new ethpipe object.
XEth Methods
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.
World Methods
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() *configIsListening() 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
Config Methods
Get(name string) object: returns the associated object given by thename.Exist() bool: returns whether the config object exist in ethereum's present state.
Object Methods
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.
Example
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)
}