diff options
author | obscuren <geffobscura@gmail.com> | 2014-05-29 17:49:41 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-05-29 17:49:41 +0800 |
commit | e7097641e3987420429fe47efdb678c9e4cd9ba9 (patch) | |
tree | 215b7bb2ff724c69235aa6172657e2fb108bd53c /ethpub/pub.go | |
parent | a2d01d6af8cace4ea0ef87662727659eaa1ff791 (diff) | |
download | dexon-e7097641e3987420429fe47efdb678c9e4cd9ba9.tar.gz dexon-e7097641e3987420429fe47efdb678c9e4cd9ba9.tar.zst dexon-e7097641e3987420429fe47efdb678c9e4cd9ba9.zip |
Support for namereg
Diffstat (limited to 'ethpub/pub.go')
-rw-r--r-- | ethpub/pub.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/ethpub/pub.go b/ethpub/pub.go index 6dd7798ae..6beab5cf9 100644 --- a/ethpub/pub.go +++ b/ethpub/pub.go @@ -2,8 +2,10 @@ package ethpub import ( "encoding/hex" + "fmt" "github.com/ethereum/eth-go/ethchain" "github.com/ethereum/eth-go/ethutil" + "math/big" "strings" ) @@ -95,13 +97,29 @@ func (lib *PEthereum) Create(key, valueStr, gasStr, gasPriceStr, script string) return lib.createTx(key, "", valueStr, gasStr, gasPriceStr, script) } +var namereg = ethutil.FromHex("bb5f186604d057c1c5240ca2ae0f6430138ac010") + +func GetAddressFromNameReg(stateManager *ethchain.StateManager, name string) []byte { + recp := new(big.Int).SetBytes([]byte(name)) + object := stateManager.CurrentState().GetStateObject(namereg) + reg := object.GetStorage(recp) + + return reg.Bytes() +} + func (lib *PEthereum) createTx(key, recipient, valueStr, gasStr, gasPriceStr, scriptStr string) (*PReceipt, error) { var hash []byte var contractCreation bool if len(recipient) == 0 { contractCreation = true } else { - hash = ethutil.FromHex(recipient) + // Check if an address is stored by this address + addr := GetAddressFromNameReg(lib.stateManager, recipient) + if len(addr) > 0 { + hash = addr + } else { + hash = ethutil.FromHex(recipient) + } } var keyPair *ethutil.KeyPair |