Browse Source

proto.eth.tx.base: remove `start_gas` attribute

The MMGen Project 1 week ago
parent
commit
f739f96f79

+ 10 - 10
mmgen/proto/eth/contract.py

@@ -151,12 +151,12 @@ class Token(Contract):
 
 	def make_tx_in(
 			self,
+			*,
 			to_addr,
 			amt,
-			start_gas,
+			gas,
 			gasPrice,
 			nonce,
-			*,
 			method_sig = 'transfer(address,uint256)'):
 		data = self.create_data(
 				to_addr,
@@ -164,7 +164,7 @@ class Token(Contract):
 				method_sig = method_sig)
 		return {
 			'to':       bytes.fromhex(self.addr),
-			'startgas': start_gas.toWei(),
+			'startgas': gas.toWei(),
 			'gasprice': gasPrice.toWei(),
 			'value':    0,
 			'nonce':    nonce,
@@ -173,20 +173,20 @@ class Token(Contract):
 	# used for token deployment only:
 	async def transfer(
 			self,
+			*,
 			from_addr,
 			to_addr,
 			amt,
 			key,
-			start_gas,
+			gas,
 			gasPrice,
-			*,
 			method_sig = 'transfer(address,uint256)'):
 		tx_in = self.make_tx_in(
-				to_addr,
-				amt,
-				start_gas,
-				gasPrice,
-				nonce = int(await self.rpc.call('eth_getTransactionCount', '0x'+from_addr, 'pending'), 16),
+				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)

+ 3 - 5
mmgen/proto/eth/tx/base.py

@@ -21,10 +21,9 @@ class Base(TxBase.Base):
 
 	rel_fee_desc = 'gas price'
 	rel_fee_disp = 'gas price in Gwei'
-	txobj  = None # ""
-	dfl_gas = 21000               # an approximate number, used for fee estimation purposes
-	dfl_start_gas = 21000         # the actual startgas amt used in the transaction
-	                              # for simple sends with no data, gas = start_gas = 21000
+	txobj = None
+	dfl_gas = 21000 # the startGas amt used in the transaction
+	                # for simple sends with no data, startGas = 21000
 	contract_desc = 'contract'
 	usr_contract_data = HexStr('')
 	disable_fee_check = False
@@ -76,5 +75,4 @@ class Base(TxBase.Base):
 
 class TokenBase(Base):
 	dfl_gas = 52000
-	dfl_start_gas = 60000
 	contract_desc = 'token contract'

+ 0 - 9
mmgen/proto/eth/tx/completed.py

@@ -18,15 +18,6 @@ from .base import Base, TokenBase
 class Completed(Base, TxBase.Completed):
 	fn_fee_unit = 'Mwei'
 
-	def __init__(self, *args, **kwargs):
-
-		self.txobj = {}
-
-		super().__init__(*args, **kwargs)
-
-		self.gas = self.proto.coin_amt(self.dfl_gas, from_unit='wei')
-		self.start_gas = self.proto.coin_amt(self.dfl_start_gas, from_unit='wei')
-
 	def check_swap_memo(self):
 		pass
 

+ 2 - 3
mmgen/proto/eth/tx/new.py

@@ -34,10 +34,9 @@ class New(Base, TxBase.New):
 		super().__init__(*args, **kwargs)
 
 		if self.cfg.gas:
-			self.gas = self.start_gas = self.proto.coin_amt(int(self.cfg.gas), from_unit='wei')
+			self.gas = self.proto.coin_amt(int(self.cfg.gas), from_unit='wei')
 		else:
 			self.gas = self.proto.coin_amt(self.dfl_gas, from_unit='wei')
-			self.start_gas = self.proto.coin_amt(self.dfl_start_gas, from_unit='wei')
 
 		if self.cfg.contract_data:
 			m = "'--contract-data' option may not be used with token transaction"
@@ -56,7 +55,7 @@ class New(Base, TxBase.New):
 			'to':   self.outputs[0].addr if self.outputs else None,
 			'amt':  self.outputs[0].amt if self.outputs else self.proto.coin_amt('0'),
 			'gasPrice': self.fee_abs2gasprice(self.usr_fee),
-			'startGas': self.start_gas,
+			'startGas': self.gas,
 			'nonce': await self.get_nonce(),
 			'chainId': self.rpc.chainID,
 			'data':  self.usr_contract_data}

+ 1 - 1
mmgen/proto/eth/tx/signed.py

@@ -44,7 +44,7 @@ class Signed(Completed, TxBase.Signed):
 			self.disable_fee_check = True
 		txid = CoinTxID(etx.hash.hex())
 		assert txid == self.coin_txid, "txid in tx.serialized doesn't match value in MMGen transaction file"
-		self.gas = o['startGas'] # approximate, but better than nothing
+		self.gas = o['startGas']
 		self.txobj = o
 		return d # 'token_addr', 'decimals' required by Token subclass
 

+ 2 - 2
mmgen/proto/eth/tx/unsigned.py

@@ -36,7 +36,7 @@ class Unsigned(Completed, TxBase.Unsigned):
 			'nonce':    ETHNonce(d['nonce']),
 			'chainId':  None if d['chainId'] == 'None' else Int(d['chainId']),
 			'data':     HexStr(d['data'])}
-		self.gas = o['startGas'] # approximate, but better than nothing
+		self.gas = o['startGas']
 		self.txobj = o
 		return d # 'token_addr', 'decimals' required by Token subclass
 
@@ -115,7 +115,7 @@ class TokenUnsigned(TokenCompleted, Unsigned):
 		tx_in = t.make_tx_in(
 				to_addr   = o['to'],
 				amt       = o['amt'],
-				start_gas = self.start_gas,
+				gas       = self.gas,
 				gasPrice  = o['gasPrice'],
 				nonce     = o['nonce'])
 		res = await t.txsign(tx_in, wif, o['from'], chain_id=o['chainId'])

+ 5 - 5
test/cmdtest_d/ct_ethdev.py

@@ -1134,11 +1134,11 @@ class CmdTestEthdev(CmdTestBase, CmdTestShared):
 				imsg('dev token balance (pre-send): {}'.format(await tk.get_balance(dfl_devaddr)))
 				imsg(f'Sending {amt} {self.proto.dcoin} to address {usr_addrs[i]} ({usr_mmaddrs[i]})')
 				txid = await tk.transfer(
-					dfl_devaddr,
-					usr_addrs[i],
-					amt,
-					dfl_devkey,
-					start_gas = self.proto.coin_amt(60000, from_unit='wei'),
+					from_addr = dfl_devaddr,
+					to_addr   = usr_addrs[i],
+					amt       = amt,
+					key       = dfl_devkey,
+					gas       = self.proto.coin_amt(60000, from_unit='wei'),
 					gasPrice  = self.proto.coin_amt(8, from_unit='Gwei'))
 				if (await self.get_tx_receipt(txid)).status == 0:
 					die(2, 'Transfer of token funds failed. Aborting')