Minor fixes and sample coin "improvements"

This commit is contained in:
obscuren
2014-04-24 00:01:22 +02:00
parent 43f1214f97
commit bb72347acf
8 changed files with 112 additions and 27 deletions

View File

@@ -8,7 +8,7 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethutil"
"github.com/niemeyer/qml"
"github.com/go-qml/qml"
"math/big"
"strings"
)
@@ -24,6 +24,18 @@ type Tx struct {
Contract bool
}
type Key struct {
Address string
}
type KeyRing struct {
Keys []interface{}
}
func NewKeyRing(keys []interface{}) *KeyRing {
return &KeyRing{Keys: keys}
}
func NewTxFromTransaction(tx *ethchain.Transaction) *Tx {
hash := hex.EncodeToString(tx.Hash())
sender := hex.EncodeToString(tx.Recipient)

View File

@@ -10,6 +10,20 @@ import (
"strings"
)
type Contract struct {
object *ethchain.StateObject
}
func NewContract(object *ethchain.StateObject) *Contract {
return &Contract{object: object}
}
func (c *Contract) GetStorage(address string) string {
val := c.object.GetMem(ethutil.Big("0x" + address))
return val.BigInt().String()
}
type EthLib struct {
stateManager *ethchain.StateManager
blockChain *ethchain.BlockChain
@@ -43,6 +57,16 @@ 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) GetKey() string {
return ethutil.Hex(ethutil.Config.Db.GetKeys()[0].Address())
}
func (lib *EthLib) GetStateObject(address string) *Contract {
stateObject := lib.stateManager.ProcState().GetContract(ethutil.FromHex(address))
return NewContract(stateObject)
}
func (lib *EthLib) CreateTx(recipient, valueStr, gasStr, gasPriceStr, dataStr string) (string, error) {
var hash []byte
var contractCreation bool

View File

@@ -7,7 +7,7 @@ import (
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/go-ethereum/utils"
"github.com/niemeyer/qml"
"github.com/go-qml/qml"
"os"
"path"
"path/filepath"