aboutsummaryrefslogtreecommitdiffstats
path: root/ethpub
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2014-06-25 23:13:27 +0800
committerzelig <viktor.tron@gmail.com>2014-06-25 23:13:27 +0800
commit4141cc39d0aa3956313aa4aa912ad81858f9bbc3 (patch)
tree4ada58c75c1d82fc65cb6ef4e6ec48e0c8604993 /ethpub
parentf58c7ac5a6f5d77649c1c07dce94bf6d5c146c31 (diff)
parentd8c675afbf98178ffa447e4d36b77bbdad3f9ec0 (diff)
downloaddexon-4141cc39d0aa3956313aa4aa912ad81858f9bbc3.tar
dexon-4141cc39d0aa3956313aa4aa912ad81858f9bbc3.tar.gz
dexon-4141cc39d0aa3956313aa4aa912ad81858f9bbc3.tar.bz2
dexon-4141cc39d0aa3956313aa4aa912ad81858f9bbc3.tar.lz
dexon-4141cc39d0aa3956313aa4aa912ad81858f9bbc3.tar.xz
dexon-4141cc39d0aa3956313aa4aa912ad81858f9bbc3.tar.zst
dexon-4141cc39d0aa3956313aa4aa912ad81858f9bbc3.zip
Merge remote-tracking branch 'upstream/develop' into feature/logging
Diffstat (limited to 'ethpub')
-rw-r--r--ethpub/pub.go35
-rw-r--r--ethpub/types.go1
2 files changed, 34 insertions, 2 deletions
diff --git a/ethpub/pub.go b/ethpub/pub.go
index a49ee2f12..647e689ce 100644
--- a/ethpub/pub.go
+++ b/ethpub/pub.go
@@ -1,7 +1,9 @@
package ethpub
import (
+ "bytes"
"encoding/hex"
+ "encoding/json"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethlog"
@@ -84,6 +86,36 @@ func (lib *PEthereum) GetCoinBase() string {
return lib.SecretToAddress(hex.EncodeToString(key))
}
+func (lib *PEthereum) GetTransactionsFor(address string, asJson bool) interface{} {
+ sBlk := lib.manager.BlockChain().LastBlockHash
+ blk := lib.manager.BlockChain().GetBlock(sBlk)
+ addr := []byte(ethutil.FromHex(address))
+
+ var txs []*PTx
+
+ for ; blk != nil; blk = lib.manager.BlockChain().GetBlock(sBlk) {
+ sBlk = blk.PrevHash
+
+ // Loop through all transactions to see if we missed any while being offline
+ for _, tx := range blk.Transactions() {
+ if bytes.Compare(tx.Sender(), addr) == 0 || bytes.Compare(tx.Recipient, addr) == 0 {
+ ptx := NewPTx(tx)
+ //TODO: somehow move this to NewPTx
+ ptx.Confirmations = int(lib.manager.BlockChain().LastBlockNumber - blk.BlockInfo().Number)
+ txs = append(txs, ptx)
+ }
+ }
+ }
+ if asJson {
+ txJson, err := json.Marshal(txs)
+ if err != nil {
+ return nil
+ }
+ return string(txJson)
+ }
+ return txs
+}
+
func (lib *PEthereum) GetStorage(address, storageAddress string) string {
return lib.GetStateObject(address).GetStorage(storageAddress)
}
@@ -126,7 +158,6 @@ func GetAddressFromNameReg(stateManager *ethchain.StateManager, name string) []b
return nil
}
-
func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, scriptStr string) (*PReceipt, error) {
var hash []byte
var contractCreation bool
@@ -145,7 +176,7 @@ func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, sc
var keyPair *ethutil.KeyPair
var err error
if key[0:2] == "0x" {
- keyPair, err = ethutil.NewKeyPairFromSec([]byte(ethutil.FromHex(key[0:2])))
+ keyPair, err = ethutil.NewKeyPairFromSec([]byte(ethutil.FromHex(key[2:])))
} else {
keyPair, err = ethutil.NewKeyPairFromSec([]byte(ethutil.FromHex(key)))
}
diff --git a/ethpub/types.go b/ethpub/types.go
index 352598148..0ced68ad1 100644
--- a/ethpub/types.go
+++ b/ethpub/types.go
@@ -99,6 +99,7 @@ type PTx struct {
Data string `json:"data"`
Contract bool `json:"isContract"`
CreatesContract bool `json:"createsContract"`
+ Confirmations int `json:"confirmations"`
}
func NewPTx(tx *ethchain.Transaction) *PTx {