22
33namespace Farbcode \LaravelEvm \Clients ;
44
5+ use Farbcode \LaravelEvm \Contracts \AbiCodec ;
6+ use Farbcode \LaravelEvm \Contracts \ContractClient ;
7+ use Farbcode \LaravelEvm \Contracts \FeePolicy ;
8+ use Farbcode \LaravelEvm \Contracts \NonceManager ;
59use Farbcode \LaravelEvm \Contracts \RpcClient ;
610use Farbcode \LaravelEvm \Contracts \Signer ;
7- use Farbcode \LaravelEvm \Contracts \NonceManager ;
8- use Farbcode \LaravelEvm \Contracts \FeePolicy ;
911use Farbcode \LaravelEvm \Contracts \TxBuilder ;
10- use Farbcode \LaravelEvm \Contracts \AbiCodec ;
11- use Farbcode \LaravelEvm \Contracts \ContractClient ;
12-
1312use Farbcode \LaravelEvm \Jobs \SendTransaction ;
1413
1514class ContractClientGeneric implements ContractClient
1615{
1716 public function __construct (
18- private RpcClient $ rpc ,
19- private Signer $ signer ,
17+ private RpcClient $ rpc ,
18+ private Signer $ signer ,
2019 private NonceManager $ nonces ,
21- private FeePolicy $ fees ,
22- private TxBuilder $ builder ,
23- private AbiCodec $ abi ,
24- private int $ chainId ,
25- private array $ txCfg
26- )
27- {
28- }
20+ private FeePolicy $ fees ,
21+ private TxBuilder $ builder ,
22+ private AbiCodec $ abi ,
23+ private int $ chainId ,
24+ private array $ txCfg
25+ ) {}
2926
3027 private string $ address = '' ;
28+
3129 private array |string $ abiJson = [];
3230
3331 public function at (string $ address , array |string $ abi = []): self
3432 {
3533 $ this ->address = $ address ;
3634 $ this ->abiJson = $ abi ;
35+
3736 return $ this ;
3837 }
3938
@@ -45,7 +44,7 @@ public function call(string $function, array $args = []): mixed
4544 return $ this ->rpc ->call ('eth_call ' , [[
4645 'from ' => $ from ,
4746 'to ' => $ this ->address ,
48- 'data ' => $ data
47+ 'data ' => $ data,
4948 ], 'latest ' ]);
5049 }
5150
@@ -55,17 +54,18 @@ public function estimateGas(string $data, ?string $from = null): int
5554 $ est = $ this ->rpc ->call ('eth_estimateGas ' , [[
5655 'from ' => $ from ,
5756 'to ' => $ this ->address ,
58- 'data ' => $ data
57+ 'data ' => $ data,
5958 ]]);
60- $ n = is_string ($ est ) ? hexdec ($ est ) : (int )$ est ;
61- $ pad = (float )($ this ->txCfg ['estimate_padding ' ] ?? 1.2 );
62- return (int )max (150000 , ceil ($ n * $ pad ));
59+ $ n = is_string ($ est ) ? hexdec ($ est ) : (int ) $ est ;
60+ $ pad = (float ) ($ this ->txCfg ['estimate_padding ' ] ?? 1.2 );
61+
62+ return (int ) max (150000 , ceil ($ n * $ pad ));
6363 }
6464
6565 public function sendAsync (string $ function , array $ args = [], array $ opts = []): string
6666 {
6767 $ data = $ this ->abi ->encodeFunction ($ this ->abiJson , $ function , $ args );
68- $ queue = (string )($ this ->txCfg ['queue ' ] ?? 'evm-send ' );
68+ $ queue = (string ) ($ this ->txCfg ['queue ' ] ?? 'evm-send ' );
6969
7070 return dispatch (
7171 new SendTransaction (
@@ -83,11 +83,12 @@ public function wait(string $txHash, int $timeoutSec = 120, int $pollMs = 800):
8383 $ deadline = time () + $ timeoutSec ;
8484 while (time () < $ deadline ) {
8585 $ rec = $ this ->rpc ->call ('eth_getTransactionReceipt ' , [$ txHash ]);
86- if (!empty ($ rec )) {
86+ if (! empty ($ rec )) {
8787 return $ rec ;
8888 }
8989 usleep ($ pollMs * 1000 );
9090 }
91+
9192 return null ;
9293 }
9394}
0 commit comments