mirror of
git://holbrook.no/eth-address-index
synced 2024-11-16 14:36:46 +01:00
Add token index executables
This commit is contained in:
parent
d659ae72f5
commit
28abd891dc
@ -1 +0,0 @@
|
|||||||
from .token import TokenEndorser
|
|
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
|||||||
[{"inputs":[{"internalType":"string","name":"_name","type":"string"},{"internalType":"string","name":"_symbol","type":"string"},{"internalType":"uint8","name":"_decimals","type":"uint8"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_from","type":"address"},{"indexed":true,"internalType":"address","name":"_to","type":"address"},{"indexed":true,"internalType":"address","name":"_spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"}],"name":"TransferFrom","type":"event"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"addMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"allowances","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_spender","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"approve","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"decimals","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"mint","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_minter","type":"address"}],"name":"removeMinter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"transferFrom","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
|
|
File diff suppressed because one or more lines are too long
@ -1 +0,0 @@
|
|||||||
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":true,"internalType":"address","name":"_adder","type":"address"},{"indexed":true,"internalType":"uint256","name":"_index","type":"uint256"},{"indexed":false,"internalType":"bytes32","name":"_data","type":"bytes32"}],"name":"EndorsementAdded","type":"event"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"bytes32","name":"_data","type":"bytes32"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"endorsement","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"endorser","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"endorserTokenCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"tokenIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"","type":"string"}],"name":"tokenSymbolIndex","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"tokens","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]
|
|
@ -1,79 +0,0 @@
|
|||||||
# Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
# File-version: 1
|
|
||||||
# Description: Python interface to abi and bin files for faucet contracts
|
|
||||||
|
|
||||||
# standard imports
|
|
||||||
import logging
|
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import hashlib
|
|
||||||
|
|
||||||
logg = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
moddir = os.path.dirname(__file__)
|
|
||||||
datadir = os.path.join(moddir, 'data')
|
|
||||||
|
|
||||||
|
|
||||||
class TokenEndorser:
|
|
||||||
|
|
||||||
__abi = None
|
|
||||||
__bytecode = None
|
|
||||||
__address = None
|
|
||||||
|
|
||||||
def __init__(self, w3, address, signer_address=None):
|
|
||||||
abi = TokenEndorser.abi()
|
|
||||||
TokenEndorser.bytecode()
|
|
||||||
self.__address = address
|
|
||||||
self.contract = w3.eth.contract(abi=abi, address=address)
|
|
||||||
self.w3 = w3
|
|
||||||
if signer_address != None:
|
|
||||||
self.signer_address = signer_address
|
|
||||||
else:
|
|
||||||
if type(self.w3.eth.defaultAccount).__name__ == 'Empty':
|
|
||||||
self.w3.eth.defaultAccount = self.w3.eth.accounts[0]
|
|
||||||
self.signer_address = self.w3.eth.defaultAccount
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def abi():
|
|
||||||
if TokenEndorser.__abi == None:
|
|
||||||
f = open(os.path.join(datadir, 'TokenEndorser.json'), 'r')
|
|
||||||
TokenEndorser.__abi = json.load(f)
|
|
||||||
f.close()
|
|
||||||
return TokenEndorser.__abi
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def bytecode():
|
|
||||||
if TokenEndorser.__bytecode == None:
|
|
||||||
f = open(os.path.join(datadir, 'TokenEndorser.bin'))
|
|
||||||
TokenEndorser.__bytecode = f.read()
|
|
||||||
f.close()
|
|
||||||
return TokenEndorser.__bytecode
|
|
||||||
|
|
||||||
|
|
||||||
def token_from_symbol(self, symbol):
|
|
||||||
return self.contract.functions.tokenSymbolIndex(symbol).call()
|
|
||||||
|
|
||||||
|
|
||||||
def endorsed_tokens(self, endorser_address):
|
|
||||||
tokens = []
|
|
||||||
for i in range(self.contract.functions.endorserTokenCount(endorser_address).call()):
|
|
||||||
tidx = self.contract.functions.endorser(endorser_address, i).call()
|
|
||||||
t = self.contract.functions.tokens(tidx).call()
|
|
||||||
tokens.append(t)
|
|
||||||
return tokens
|
|
||||||
|
|
||||||
|
|
||||||
def add(self, token_address, data):
|
|
||||||
self.contract.functions.add(token_address, data).transact({'from': self.signer_address})
|
|
||||||
|
|
||||||
|
|
||||||
def to_endorsement_key(token_address_hex, endorser_address_hex):
|
|
||||||
h = hashlib.new('sha256')
|
|
||||||
h.update(bytes.fromhex(token_address_hex[2:]))
|
|
||||||
h.update(bytes.fromhex(endorser_address_hex[2:]))
|
|
||||||
return h.digest()
|
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
|||||||
"""Adds a new token endorsement
|
"""Adds a new token to the token symbol index
|
||||||
|
|
||||||
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
||||||
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||||
@ -10,6 +10,7 @@ import os
|
|||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
|
import hashlib
|
||||||
|
|
||||||
# third-party imports
|
# third-party imports
|
||||||
import web3
|
import web3
|
||||||
@ -26,12 +27,11 @@ data_dir = os.path.join(script_dir, '..', 'data')
|
|||||||
|
|
||||||
argparser = argparse.ArgumentParser()
|
argparser = argparse.ArgumentParser()
|
||||||
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
|
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
|
||||||
argparser.add_argument('-a', '--contract-address', dest='a', type=str, help='Token endorsement contract address')
|
argparser.add_argument('-r', '--contract-address', dest='r', type=str, help='Token endorsement contract address')
|
||||||
argparser.add_argument('-t', '--token-address', dest='t', type=str, help='Contract address of token to endorse')
|
argparser.add_argument('-o', '--owner-address', dest='o', type=str, help='Address to use to sign endorsement transaction')
|
||||||
argparser.add_argument('-o', '--endorser-address', dest='o', type=str, help='Address to use to sign endorsement transaction')
|
|
||||||
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir))
|
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir))
|
||||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
||||||
argparser.add_argument('sha256hash', type=str, help='SHA256 sum of endorsement data')
|
argparser.add_argument('address', type=str, help='Ethereum address to add declaration to')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
if args.v:
|
if args.v:
|
||||||
@ -40,18 +40,30 @@ if args.v:
|
|||||||
def main():
|
def main():
|
||||||
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
|
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
|
||||||
|
|
||||||
f = open(os.path.join(args.abi_dir, 'TokenEndorser.json'), 'r')
|
f = open(os.path.join(args.abi_dir, 'TokenUniqueSymbolIndex.json'), 'r')
|
||||||
abi = json.load(f)
|
abi = json.load(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
f = open(os.path.join(args.abi_dir, 'ERC20.json'), 'r')
|
||||||
|
erc20_abi = json.load(f)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
t = w3.eth.contract(abi=erc20_abi, address=args.address)
|
||||||
|
token_symbol = t.functions.symbol().call()
|
||||||
|
|
||||||
w3.eth.defaultAccount = w3.eth.accounts[0]
|
w3.eth.defaultAccount = w3.eth.accounts[0]
|
||||||
if args.o != None:
|
if args.o != None:
|
||||||
w3.eth.defaultAccount = args.o
|
w3.eth.defaultAccount = args.o
|
||||||
logg.debug('endorser address {}'.format(w3.eth.defaultAccount))
|
logg.debug('owner address {}'.format(w3.eth.defaultAccount))
|
||||||
|
|
||||||
c = w3.eth.contract(abi=abi, address=args.a)
|
c = w3.eth.contract(abi=abi, address=args.r)
|
||||||
|
|
||||||
tx_hash = c.functions.add(args.t, args.sha256hash).transact()
|
h = hashlib.new('sha256')
|
||||||
|
h.update(token_symbol.encode('utf-8'))
|
||||||
|
z = h.digest()
|
||||||
|
logg.info('token symbol {} => {}'.format(token_symbol, z.hex()))
|
||||||
|
|
||||||
|
tx_hash = c.functions.register('0x' + z.hex(), args.address).transact()
|
||||||
print(tx_hash.hex())
|
print(tx_hash.hex())
|
||||||
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
"""Deploys token endorsement contract
|
"""Deploys the token symbol index
|
||||||
|
|
||||||
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
|
||||||
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
||||||
@ -26,7 +26,7 @@ data_dir = os.path.join(script_dir, '..', 'data')
|
|||||||
|
|
||||||
argparser = argparse.ArgumentParser()
|
argparser = argparse.ArgumentParser()
|
||||||
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
|
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
|
||||||
argparser.add_argument('-o', '--owner', dest='o', type=str, help='Accounts index owner')
|
argparser.add_argument('-o', '--owner', dest='o', type=str, help='Accounts declarator owner')
|
||||||
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir))
|
argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir))
|
||||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
@ -37,11 +37,11 @@ if args.v:
|
|||||||
def main():
|
def main():
|
||||||
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
|
w3 = web3.Web3(web3.Web3.HTTPProvider(args.p))
|
||||||
|
|
||||||
f = open(os.path.join(args.abi_dir, 'TokenEndorser.json'), 'r')
|
f = open(os.path.join(args.abi_dir, 'TokenUniqueSymbolIndex.json'), 'r')
|
||||||
abi = json.load(f)
|
abi = json.load(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
f = open(os.path.join(args.abi_dir, 'TokenEndorser.bin'), 'r')
|
f = open(os.path.join(args.abi_dir, 'TokenUniqueSymbolIndex.bin'), 'r')
|
||||||
bytecode = f.read()
|
bytecode = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user