Skip to content
This repository was archived by the owner on Mar 5, 2020. It is now read-only.

newunregdupd #42

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions eosio.unregd/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Build
# Build (eosio.cdt >= v1.5.0)

```shell
eosiocpp -o eosio.unregd.wast eosio.unregd.cpp
eosiocpp -g eosio.unregd.abi eosio.unregd.cpp
eosio-cpp -o eosio.unregd.wasm eosio.unregd.cpp
eosio-abigen -contract=unregd -output=eosio.unregd.abi eosio.unregd.cpp -R=./ricardian
```

# Setup
Expand All @@ -17,18 +17,20 @@ You need to have nodeos running.

# Add test data

```./add_test_data.sh```
```./add_test_data.sh [nonce]```

# Claim

```shell
python claim.py eostest11125 EOS7jUtjvK61eWM38RyHS3WFM7q41pSYMP7cpjQWWjVaaxH5J9Cb7 thisisatesta@active
python claim.py eostest11125 EOS7jUtjvK61eWM38RyHS3WFM7q41pSYMP7cpjQWWjVaaxH5J9Cb7 thisisatesta@active [nonce]
```

# Dependecies

```shell
pip install bitcoin --user
pip install requests --user
sudo apt-get install python-pysha3
pip3 install bitcoin --user
pip3 install requests --user
pip3 install eth-utils --user
pip3 install pycryptodome --user
pip3 install pyrlp --user
```
5 changes: 2 additions & 3 deletions eosio.unregd/add_test_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;35m'
NC='\033[0m' # No Color

PRIV_HEX=$(openssl rand -hex 32)
ADDY=$(python get_eth_address.py $PRIV_HEX)
AMOUNT=$(python -c 'import random; print "%.4f" % (random.random()*1000)')
ADDY=$(python3 get_eth_address.py $PRIV_HEX $1)
AMOUNT=$(python3 -c 'import random; print("%.4f" % (random.random()*1000))')

echo "* Generated ETH privkey $BLUE$PRIV_HEX$NC"
echo "* Adding $GREEN$ADDY$NC to eosio.unregd db with $GREEN$AMOUNT EOS$NC"
Expand Down
40 changes: 26 additions & 14 deletions eosio.unregd/claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import time
import struct
import requests as req
from eth_utils import decode_hex
from hashlib import sha256
from bitcoin import ecdsa_raw_sign, encode_privkey
from tempfile import mktemp
from subprocess import Popen, PIPE
from sha3 import keccak_256
from getpass import getpass
from Crypto.Hash import keccak

API_URL = os.environ.get("API_URL", "http://127.0.0.1:8888")

def keccak_256(x): return keccak.new(digest_bits=256, data=x)

def url_for(url):
return '{0}{1}'.format(API_URL, url)

Expand All @@ -30,7 +33,7 @@ def is_canonical( sig ):
and not (sig[33] == 0 and not (sig[34] & 0x80))

def get_tapos_info(block_id):
block_id_bin = block_id.decode('hex')
block_id_bin = decode_hex(block_id)

hash0 = struct.unpack("<Q", block_id_bin[0:8])[0]
hash1 = struct.unpack("<Q", block_id_bin[8:16])[0]
Expand All @@ -41,15 +44,17 @@ def get_tapos_info(block_id):
return ref_block_num, ref_block_prefix

if len(sys.argv) < 3:
print "claim.py EOSACCOUNT EOSPUBKEY SIGNTXPRIV [ETHPRIV]"
print " EOSACCOUNT: Desired EOS account name"
print " EOSPUBKEY: Desired EOS pubkey"
print " PUSHER: account@permission used to sign and push the claim transaction"
print ("claim.py EOSACCOUNT EOSPUBKEY SIGNTXPRIV [ETHPRIV]")
print (" EOSACCOUNT: Desired EOS account name")
print (" EOSPUBKEY: Desired EOS pubkey")
print (" PUSHER: account@permission used to sign and push the claim transaction")
print (" NONCE: Ethereum nonce if claiming tokens controlled by contract (will call regaccount2)")
sys.exit(1)

eos_account = sys.argv[1]
eos_pub = sys.argv[2]
pusher = sys.argv[3]
nonce = int(sys.argv[4])
priv = getpass("Enter ETH private key (Wif or Hex format)")


Expand All @@ -60,32 +65,39 @@ def get_tapos_info(block_id):

msg = '%d,%d,%s,%s' % (ref_block_num, ref_block_prefix, eos_pub, eos_account)
msg = '%s%s%d%s' % ("\x19", "Ethereum Signed Message:\n", len(msg), msg)
msghash = keccak_256(msg).digest()
msghash = keccak_256(msg.encode('utf-8')).digest()

v, r, s = ecdsa_raw_sign(msghash, encode_privkey(priv,'hex').decode('hex'))
v, r, s = ecdsa_raw_sign(msghash, decode_hex(encode_privkey(priv,'hex')) )
signature = '00%02x%064x%064x' % (v,r,s)

if is_canonical(bytearray(signature.decode('hex'))):
if is_canonical(decode_hex(signature)):
break

time.sleep(1)

tempf = mktemp()
with open(tempf,'w') as fp:
fp.write(json.dumps({
params = {
'signature' : signature,
'account' : eos_account,
'eos_pubkey' : eos_pub
}))
}
action_to_call = "regaccount"

if nonce >= 0:
params['nonce'] = nonce
action_to_call = "regaccount2"

fp.write(json.dumps(params))

with open(os.devnull, 'w') as devnull:
cmd = ["cleos","-u", API_URL, "push", "action", "-r", block_id, "eosio.unregd", "regaccount", tempf, "-p", pusher]
cmd = ["cleos","-u", API_URL, "push", "action", "-r", block_id, "eosio.unregd", action_to_call, tempf, "-p", pusher]
p = Popen(cmd)
output, err = p.communicate("")

if p.returncode:
print "Error sending tx"
print ("Error sending tx")
sys.exit(1)

print "tx sent"
print ("tx sent")
sys.exit(0)
Loading