Skip to content

Commit

Permalink
added get blocktime call
Browse files Browse the repository at this point in the history
  • Loading branch information
Ekliptor authored and Ekliptor committed Jul 7, 2019
1 parent e2f3e03 commit e2863aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ returns `int` - The number of confirmations or -1 if the $transactionID doesn't
---

##### createNewAddress(string $xPub, int $addressCount, string $hdPathFormat = '0/%d'): ?BchAddress
Creates a new address from the xPub. It will automatically increment the counter in the hdPath parameter to derive the next deterministic address.
Creates a new address from the xPub.
* `string $xPub` - The extended public key. Called 'Master Public Key' in Electron Cash.
* `int $addressCount` - The number of the next address to generate a unique address. Usually this should be an incrementing integer.
* `string $hdPathFormat` - (optional) The HD path to be used for creating address children.
Expand Down
10 changes: 8 additions & 2 deletions src/BlockchainApi/AbstractBlockchainApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ public function setHttpAgent(AbstractHttpAgent $agent): void {
public abstract function getConfirmationCount(string $transactionID): int;

/**
* Creates a new address from the xPub. It will automatically increment the counter in the hdPath parameter to
* derive the next deterministic address.
* Get the blocktime of the transaction.
* @param string $transactionID
* @return int The time in seconds (UNIX timestamp) or -1 if the transaction doesn't exist.
*/
public abstract function getBlocktime(string $transactionID): int;

/**
* Creates a new address from the xPub.
* @param string $xPub The extended public key. Called 'Master Public Key' in Electron Cash.
* @param int $addressCount The number of the next address to generate a unique address. Usually this should be an incrementing integer.
* @param string $hdPathFormat (optional) The HD path to be used for creating address children.
Expand Down
7 changes: 7 additions & 0 deletions src/BlockchainApi/BitcoinComRestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public function getConfirmationCount(string $transactionID): int {
return (int)$txDetails->confirmations;
}

public function getBlocktime(string $transactionID): int {
$txDetails = $this->getTransactionDetails($transactionID);
if (!$txDetails || !isset($txDetails->blocktime))
return -1; // not found
return (int)$txDetails->blocktime;
}

public function createNewAddress(string $xPub, int $addressCount, string $hdPathFormat = '0/%d'): ?BchAddress {
$nextHdPath = sprintf($hdPathFormat, $addressCount); // since update on 2019-06-05 only works with plain numbers
$url = sprintf($this->blockchainApiUrl . 'address/fromXPub/%s?hdPath=%s', $xPub, $nextHdPath);
Expand Down

0 comments on commit e2863aa

Please sign in to comment.