Skip to content

Commit 00fb7e5

Browse files
committed
Add env to message bus
1 parent d2d7cb4 commit 00fb7e5

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/Worker/Client/ImmutableXClient.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class ImmutableXClient
1414
{
1515
private HttpClientInterface $httpClient;
1616

17+
private string $env = 'prod';
18+
1719
public function __construct(
1820
private readonly string $publicKey,
1921
private readonly string $privateKey,
@@ -22,9 +24,14 @@ public function __construct(
2224
$this->httpClient = HttpClient::create();
2325
}
2426

27+
public function setEnv(string $env): void
28+
{
29+
$this->env = $env;
30+
}
31+
2532
public function transferNft(array $payload): array
2633
{
27-
$response = $this->httpClient->request('POST', 'https://api.x.immutable.com/v1/signable-transfer-details', [
34+
$response = $this->httpClient->request('POST', $this->getIMXEndpoint() . '/v1/signable-transfer-details', [
2835
'json' => [
2936
'amount' => '1',
3037
'receiver' => $payload['recipient'],
@@ -55,7 +62,7 @@ public function transferToken(array $payload): array
5562
$tokenData['token_address'] = TokenHelper::getTokenContract($payload['token']['token_type']);
5663
}
5764

58-
$response = $this->httpClient->request('POST', 'https://api.x.immutable.com/v1/signable-transfer-details', [
65+
$response = $this->httpClient->request('POST', $this->getIMXEndpoint() . '/v1/signable-transfer-details', [
5966
'json' => [
6067
'amount' => $payload['token']['quantity'],
6168
'receiver' => $payload['recipient'],
@@ -80,7 +87,7 @@ private function transfer(array $resultSignable): array
8087
$starkNetSigner = new StarkSigner($this->publicKey, $this->privateKey);
8188
$starkSignature = $starkNetSigner->signMessage($resultSignable['payload_hash']);
8289

83-
$response = $this->httpClient->request('POST', 'https://api.x.immutable.com/v1/transfers', [
90+
$response = $this->httpClient->request('POST', $this->getIMXEndpoint() . '/v1/transfers', [
8491
'headers' => [
8592
'x-imx-eth-address' => $this->publicKey,
8693
'x-imx-eth-signature' => $ethereumSignature,
@@ -100,4 +107,9 @@ private function transfer(array $resultSignable): array
100107

101108
return $response->toArray();
102109
}
110+
111+
private function getIMXEndpoint(): string
112+
{
113+
return $this->env === 'dev' ? 'https://api.ropsten.x.immutable.com' : 'https://api.x.immutable.com';
114+
}
103115
}

src/Worker/Command/RunCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ private function runProcess(): int
8787
}
8888

8989
if (in_array($message['task'], self::ALLOWED_TASKS)) {
90+
91+
$this->immutableXClient->setEnv($result['environment']);
92+
9093
try {
9194
switch ($message['task']) {
9295
case 'task-transfer-nft':

0 commit comments

Comments
 (0)