@@ -99,3 +99,73 @@ def reconcile_kudos_preferred_wallet(profile):
9999 profile .save ()
100100
101101 return profile .preferred_kudos_wallet
102+
103+
104+ def re_send_kudos_transfer (kt , override_with_xdai_okay ):
105+ from dashboard .utils import get_web3 , has_tx_mined
106+ from gas .utils import recommend_min_gas_price_to_confirm_in_time
107+ from kudos .utils import kudos_abi
108+ from web3 import Web3
109+ from kudos .models import KudosTransfer
110+ from django .utils import timezone
111+
112+ gas_clear_within_mins = 1
113+ gas_multiplier = 1.2
114+
115+ if not kt .kudos_token_cloned_from .is_owned_by_gitcoin :
116+ print (f'{ kt .id } => not owned by gitcoin' )
117+ return
118+
119+ network = kt .network
120+ if network == 'mainnet' :
121+ if kt .kudos_token_cloned_from .on_xdai and override_with_xdai_okay :
122+ network = 'xdai'
123+ kt .network = 'xdai'
124+ kt .kudos_token_cloned_from = kt .kudos_token_cloned_from .on_xdai
125+ kt .save ()
126+ w3 = get_web3 (network )
127+ kudos_contract_address = Web3 .toChecksumAddress (settings .KUDOS_CONTRACT_MAINNET )
128+ if network == 'xdai' :
129+ kudos_contract_address = Web3 .toChecksumAddress (settings .KUDOS_CONTRACT_XDAI )
130+ kudos_owner_address = Web3 .toChecksumAddress (settings .KUDOS_OWNER_ACCOUNT )
131+ nonce = w3 .eth .getTransactionCount (kudos_owner_address )
132+
133+ token_id = kt .kudos_token_cloned_from .token_id
134+ address = kt .receive_address
135+ if not address :
136+ address = kt .recipient_profile .preferred_payout_address
137+ if not address :
138+ address = kt .recipient_profile .last_observed_payout_address
139+ price_finney = kt .kudos_token_cloned_from .price_finney
140+
141+ try :
142+
143+ contract = w3 .eth .contract (Web3 .toChecksumAddress (kudos_contract_address ), abi = kudos_abi ())
144+ gasPrice = int (gas_multiplier * float (recommend_min_gas_price_to_confirm_in_time (gas_clear_within_mins )) * 10 ** 9 )
145+ if network == 'xdai' :
146+ gasPrice = 1 * 10 ** 9
147+ tx = contract .functions .clone (Web3 .toChecksumAddress (address ), token_id , 1 ).buildTransaction ({
148+ 'nonce' : nonce ,
149+ 'gas' : 500000 ,
150+ 'gasPrice' : gasPrice ,
151+ 'value' : int (price_finney / 1000.0 * 10 ** 18 ),
152+ })
153+
154+ signed = w3 .eth .account .signTransaction (tx , settings .KUDOS_PRIVATE_KEY )
155+ txid = w3 .eth .sendRawTransaction (signed .rawTransaction ).hex ()
156+ nonce += 1
157+ print (f'sent tx nonce:{ nonce } for kt:{ kt .id } on { network } ' )
158+ kt .txid = txid
159+ kt .receive_txid = txid
160+ kt .tx_status = 'pending'
161+ kt .receive_tx_status = 'pending'
162+ kt .network = network
163+ kt .tx_time = timezone .now ()
164+ kt .receive_tx_time = timezone .now ()
165+ kt .save ()
166+ return txid
167+
168+ except Exception as e :
169+ print (e )
170+ error = "Could not redeem your kudos. Please try again soon."
171+ return None
0 commit comments