@@ -132,6 +132,44 @@ defmodule API.TX do
132132 end
133133 end
134134
135+ def submit_and_wait ( tx_packed , broadcast \\ true ) do
136+ result = TX . validate ( tx_packed )
137+ if result [ :error ] == :ok do
138+ txu = TX . unpack ( tx_packed )
139+ if tx_packed =~ "deploy" do
140+ action = hd ( txu . tx . actions )
141+ if action . contract == "Contract" and action . function == "deploy" do
142+ case BIC.Contract . validate ( List . first ( action . args ) ) do
143+ % { error: :ok } ->
144+ if broadcast do TXPool . insert_and_broadcast ( tx_packed ) else TXPool . insert ( tx_packed ) end
145+ txres = submit_and_wait_1 ( result . txu . hash )
146+ % { error: :ok , hash: Base58 . encode ( result . txu . hash ) , entry_hash: txres . metadata . entry_hash , result: txres [ :result ] }
147+ error -> error
148+ end
149+ else
150+ if broadcast do TXPool . insert_and_broadcast ( tx_packed ) else TXPool . insert ( tx_packed ) end
151+ txres = submit_and_wait_1 ( result . txu . hash )
152+ % { error: :ok , hash: Base58 . encode ( result . txu . hash ) , entry_hash: txres . metadata . entry_hash , result: txres [ :result ] }
153+ end
154+ else
155+ if broadcast do TXPool . insert_and_broadcast ( tx_packed ) else TXPool . insert ( tx_packed ) end
156+ txres = submit_and_wait_1 ( result . txu . hash )
157+ % { error: :ok , hash: Base58 . encode ( result . txu . hash ) , entry_hash: txres . metadata . entry_hash , result: txres [ :result ] }
158+ end
159+ else
160+ % { error: result . error }
161+ end
162+ end
163+
164+ def submit_and_wait_1 ( hash , 30 ) do nil end
165+ def submit_and_wait_1 ( hash , tries \\ 0 ) do
166+ tx = get ( hash )
167+ if tx do tx else
168+ Process . sleep ( 100 )
169+ submit_and_wait_1 ( hash , tries + 1 )
170+ end
171+ end
172+
135173 def format_tx_for_client ( nil ) do nil end
136174 def format_tx_for_client ( tx ) do
137175 tx = Map . drop ( tx , [ :tx_encoded ] )
0 commit comments