aboutsummaryrefslogtreecommitdiffstats
path: root/ui/library.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-02-22 00:29:59 +0800
committerobscuren <geffobscura@gmail.com>2014-02-22 00:29:59 +0800
commit3e8b27c9dc78ffeeefae987e67730fae17707df4 (patch)
treeccc51eac0f5772d3500b6555325ec97c55a7f0b0 /ui/library.go
parent95a48cea18eccd4ea2cb298027dbd01bd21f43e8 (diff)
downloadgo-tangerine-3e8b27c9dc78ffeeefae987e67730fae17707df4.tar
go-tangerine-3e8b27c9dc78ffeeefae987e67730fae17707df4.tar.gz
go-tangerine-3e8b27c9dc78ffeeefae987e67730fae17707df4.tar.bz2
go-tangerine-3e8b27c9dc78ffeeefae987e67730fae17707df4.tar.lz
go-tangerine-3e8b27c9dc78ffeeefae987e67730fae17707df4.tar.xz
go-tangerine-3e8b27c9dc78ffeeefae987e67730fae17707df4.tar.zst
go-tangerine-3e8b27c9dc78ffeeefae987e67730fae17707df4.zip
WIP library, sample app
Diffstat (limited to 'ui/library.go')
-rw-r--r--ui/library.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/ui/library.go b/ui/library.go
new file mode 100644
index 000000000..36952e198
--- /dev/null
+++ b/ui/library.go
@@ -0,0 +1,42 @@
+package ethui
+
+import (
+ "encoding/hex"
+ "fmt"
+ "github.com/ethereum/eth-go/ethchain"
+ "github.com/ethereum/eth-go/ethutil"
+ "math/big"
+)
+
+type EthLib struct {
+ blockManager *ethchain.BlockManager
+ blockChain *ethchain.BlockChain
+ txPool *ethchain.TxPool
+}
+
+func (lib *EthLib) CreateTx(receiver string, amount uint64) string {
+ hash, err := hex.DecodeString(receiver)
+ if err != nil {
+ return err.Error()
+ }
+
+ tx := ethchain.NewTransaction(hash, big.NewInt(int64(amount)), []string{""})
+ data, _ := ethutil.Config.Db.Get([]byte("KeyRing"))
+ keyRing := ethutil.NewValueFromBytes(data)
+ tx.Sign(keyRing.Get(0).Bytes())
+
+ lib.txPool.QueueTransaction(tx)
+
+ return ethutil.Hex(tx.Hash())
+}
+
+func (lib *EthLib) GetBlock(hexHash string) *Block {
+ hash, err := hex.DecodeString(hexHash)
+ if err != nil {
+ return nil
+ }
+
+ block := lib.blockChain.GetBlock(hash)
+ fmt.Println(block)
+ return &Block{Number: int(block.BlockInfo().Number), Hash: ethutil.Hex(block.Hash())}
+}