proto.eth.contract: methods relocate, whitespace

This commit is contained in:
The MMGen Project 2025-03-25 09:46:01 +00:00
commit 5c5086fcb6
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
2 changed files with 19 additions and 19 deletions

View file

@ -42,14 +42,6 @@ class Contract:
def create_method_id(self, sig):
return self.keccak_256(sig.encode()).hexdigest()[:8]
def transferdata2sendaddr(self, data): # online
return CoinAddr(self.proto, parse_abi(data)[1][-40:])
def transferdata2amt(self, data): # online
return self.proto.coin_amt(
int(parse_abi(data)[-1], 16) * self.base_unit,
from_decimal = True)
async def code(self):
return (await self.rpc.call('eth_getCode', '0x'+self.addr))[2:]
@ -169,6 +161,14 @@ class Token(Contract):
'nonce': nonce,
'data': bytes.fromhex(data)}
def transferdata2sendaddr(self, data): # online
return CoinAddr(self.proto, parse_abi(data)[1][-40:])
def transferdata2amt(self, data): # online
return self.proto.coin_amt(
int(parse_abi(data)[-1], 16) * self.base_unit,
from_decimal = True)
# used for testing only:
async def transfer(
self,
@ -181,12 +181,12 @@ class Token(Contract):
gasPrice,
method_sig = 'transfer(address,uint256)'):
tx_in = self.make_tx_in(
to_addr = to_addr,
amt = amt,
gas = gas,
gasPrice = gasPrice,
nonce = int(await self.rpc.call('eth_getTransactionCount', '0x'+from_addr, 'pending'), 16),
method_sig = method_sig)
to_addr = to_addr,
amt = amt,
gas = gas,
gasPrice = gasPrice,
nonce = int(await self.rpc.call('eth_getTransactionCount', '0x'+from_addr, 'pending'), 16),
method_sig = method_sig)
res = await self.txsign(tx_in, key, from_addr)
return await self.txsend(res.txhex)

View file

@ -114,11 +114,11 @@ class TokenUnsigned(TokenCompleted, Unsigned):
async def do_sign(self, o, wif):
t = Token(self.cfg, self.proto, o['token_addr'], o['decimals'])
tx_in = t.make_tx_in(
to_addr = o['to'],
amt = o['amt'],
gas = self.gas,
gasPrice = o['gasPrice'],
nonce = o['nonce'])
to_addr = o['to'],
amt = o['amt'],
gas = self.gas,
gasPrice = o['gasPrice'],
nonce = o['nonce'])
res = await t.txsign(tx_in, wif, o['from'], chain_id=o['chainId'])
self.serialized = res.txhex
self.coin_txid = res.txid