WalletResult.php
1 <?php 2 3 namespace BitcoindRPC\Wallet; 4 5 use BitcoindRPC\RpcResponse; 6 7 class WalletResult 8 { 9 private RpcResponse $response; 10 11 public function __construct(RpcResponse $response) 12 { 13 $this->response = $response; 14 } 15 16 public function isSuccess(): bool 17 { 18 return $this->response->isSuccess(); 19 } 20 21 public function getData(): mixed 22 { 23 return $this->response->getData(); 24 } 25 26 public function getError(): ?string 27 { 28 return $this->response->getError(); 29 } 30 31 public function getStatusCode(): int 32 { 33 return $this->response->getStatusCode(); 34 } 35 36 public function toArray(): array 37 { 38 return $this->response->toArray(); 39 } 40 41 public function getTxid(): ?string 42 { 43 $data = $this->getData(); 44 if (is_array($data) && isset($data['txid'])) { 45 return $data['txid']; 46 } 47 if (is_string($data) && strlen($data) === 64) { 48 return $data; 49 } 50 return null; 51 } 52 53 public function getAddress(): ?string 54 { 55 $data = $this->getData(); 56 if (is_array($data) && isset($data['address'])) { 57 return $data['address']; 58 } 59 if (is_string($data) && (str_starts_with($data, '1') || str_starts_with($data, '3') || str_starts_with($data, 'bc1'))) { 60 return $data; 61 } 62 return null; 63 } 64 65 public function getAmount(): ?float 66 { 67 $data = $this->getData(); 68 if (is_array($data) && isset($data['amount'])) { 69 return $data['amount']; 70 } 71 if (is_numeric($data)) { 72 return (float) $data; 73 } 74 return null; 75 } 76 }