From 91f5a232bb4a26ce0ce1cc8020035956eb2669cb Mon Sep 17 00:00:00 2001 From: Maximilian Schmidt Date: Thu, 8 Jun 2023 19:26:14 +0200 Subject: [PATCH 1/4] php8 compatible --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 41193ac70..d7acb28fe 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "pleonasm/merkle-tree": "1.0.0", "composer/semver": "^1.4.0|^3.2.0", "lastguest/murmurhash": "v2.0.0", - "mdanter/ecc": "^0.5.0", + "mdanter/ecc": ">0.5.0", "bitwasp/buffertools": "^0.5.0", "bitwasp/bech32": "^0.0.1" }, From eacb3d0f084684be4e347d1ca4fe93b093fdc20e Mon Sep 17 00:00:00 2001 From: Maximilian Schmidt Date: Thu, 8 Jun 2023 22:22:01 +0200 Subject: [PATCH 2/4] SplFixedArray not longer supported with rewind and valid in PHP8.x --- .../Mutator/AbstractCollectionMutator.php | 102 +++++++----------- 1 file changed, 36 insertions(+), 66 deletions(-) diff --git a/src/Transaction/Mutator/AbstractCollectionMutator.php b/src/Transaction/Mutator/AbstractCollectionMutator.php index 222e69d03..0d2b377c7 100644 --- a/src/Transaction/Mutator/AbstractCollectionMutator.php +++ b/src/Transaction/Mutator/AbstractCollectionMutator.php @@ -3,117 +3,87 @@ declare(strict_types=1); namespace BitWasp\Bitcoin\Transaction\Mutator; +use ArrayAccess; +use Countable; +use Iterator; +use SplFixedArray; -abstract class AbstractCollectionMutator implements \Iterator, \ArrayAccess, \Countable +abstract class AbstractCollectionMutator implements Iterator, ArrayAccess, Countable { - /** - * @var \SplFixedArray - */ - protected $set; - - /** - * @return array - */ + private $array; + private $position; + + public function __construct(int $size) + { + $this->array = new SplFixedArray($size); + $this->position = 0; + } + public function all(): array { return $this->set->toArray(); } - /** - * @return bool - */ public function isNull(): bool { return count($this->set) === 0; } - /** - * @return int - */ - public function count(): int - { - return $this->set->count(); - } - - /** - * - */ public function rewind() { - $this->set->rewind(); + $this->position = 0; } - /** - * @return mixed - */ public function current() { - return $this->set->current(); + return $this->array[$this->position]; } - /** - * @return int - */ public function key() { - return $this->set->key(); + return $this->position; } - /** - * - */ public function next() { - $this->set->next(); + $this->position++; } - /** - * @return bool - */ public function valid() { - return $this->set->valid(); + return isset($this->array[$this->position]); } - /** - * @param int $offset - * @return bool - */ public function offsetExists($offset) { - return $this->set->offsetExists($offset); + return isset($this->array[$offset]); } - /** - * @param int $offset - */ - public function offsetUnset($offset) + public function offsetGet($offset) { - if (!$this->offsetExists($offset)) { - throw new \InvalidArgumentException('Offset does not exist'); - } - - $this->set->offsetUnset($offset); + return $this->array[$offset]; } - /** - * @param int $offset - * @return mixed - */ - public function offsetGet($offset) + public function offsetSet($offset, $value) { if (!$this->set->offsetExists($offset)) { throw new \OutOfRangeException('Nothing found at this offset'); } - return $this->set->offsetGet($offset); + + $this->array[$offset] = $value; } - /** - * @param int $offset - * @param mixed $value - */ - public function offsetSet($offset, $value) + public function offsetUnset($offset) + { + if (!$this->offsetExists($offset)) { + throw new \InvalidArgumentException('Offset does not exist'); + } + + unset($this->array[$offset]); + } + + public function count() { - $this->set->offsetSet($offset, $value); + return $this->array->count(); } } From fcb38ae510054f950536acbeb9dceb34d73e8562 Mon Sep 17 00:00:00 2001 From: Maximilian Schmidt Date: Sun, 11 Jun 2023 12:38:35 +0200 Subject: [PATCH 3/4] Fix spl array --- src/Transaction/Mutator/AbstractCollectionMutator.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Transaction/Mutator/AbstractCollectionMutator.php b/src/Transaction/Mutator/AbstractCollectionMutator.php index 0d2b377c7..565798765 100644 --- a/src/Transaction/Mutator/AbstractCollectionMutator.php +++ b/src/Transaction/Mutator/AbstractCollectionMutator.php @@ -21,12 +21,12 @@ public function __construct(int $size) public function all(): array { - return $this->set->toArray(); + return $this->array->toArray(); } public function isNull(): bool { - return count($this->set) === 0; + return count($this->array) === 0; } public function rewind() @@ -66,7 +66,7 @@ public function offsetGet($offset) public function offsetSet($offset, $value) { - if (!$this->set->offsetExists($offset)) { + if (!$this->array->offsetExists($offset)) { throw new \OutOfRangeException('Nothing found at this offset'); } From bd0bde0805774986c2e027f67f2ef41f8f2dc456 Mon Sep 17 00:00:00 2001 From: Maximilian Schmidt Date: Sun, 11 Jun 2023 12:54:29 +0200 Subject: [PATCH 4/4] Fix splfixedarray has not current anymore --- bitcoin | 1 + .../Mutator/AbstractCollectionMutator.php | 24 +++++++++---------- .../Mutator/InputCollectionMutator.php | 8 ------- 3 files changed, 13 insertions(+), 20 deletions(-) create mode 120000 bitcoin diff --git a/bitcoin b/bitcoin new file mode 120000 index 000000000..f3c139563 --- /dev/null +++ b/bitcoin @@ -0,0 +1 @@ +bitcoin \ No newline at end of file diff --git a/src/Transaction/Mutator/AbstractCollectionMutator.php b/src/Transaction/Mutator/AbstractCollectionMutator.php index 565798765..81841249a 100644 --- a/src/Transaction/Mutator/AbstractCollectionMutator.php +++ b/src/Transaction/Mutator/AbstractCollectionMutator.php @@ -10,23 +10,23 @@ abstract class AbstractCollectionMutator implements Iterator, ArrayAccess, Countable { - private $array; + protected $set; private $position; public function __construct(int $size) { - $this->array = new SplFixedArray($size); + $this->set = new SplFixedArray($size); $this->position = 0; } public function all(): array { - return $this->array->toArray(); + return $this->set->toArray(); } public function isNull(): bool { - return count($this->array) === 0; + return count($this->set) === 0; } public function rewind() @@ -36,7 +36,7 @@ public function rewind() public function current() { - return $this->array[$this->position]; + return $this->set[$this->position]; } public function key() @@ -51,26 +51,26 @@ public function next() public function valid() { - return isset($this->array[$this->position]); + return isset($this->set[$this->position]); } public function offsetExists($offset) { - return isset($this->array[$offset]); + return isset($this->set[$offset]); } public function offsetGet($offset) { - return $this->array[$offset]; + return $this->set[$offset]; } public function offsetSet($offset, $value) { - if (!$this->array->offsetExists($offset)) { + if (!$this->set->offsetExists($offset)) { throw new \OutOfRangeException('Nothing found at this offset'); } - $this->array[$offset] = $value; + $this->set[$offset] = $value; } public function offsetUnset($offset) @@ -79,11 +79,11 @@ public function offsetUnset($offset) throw new \InvalidArgumentException('Offset does not exist'); } - unset($this->array[$offset]); + unset($this->set[$offset]); } public function count() { - return $this->array->count(); + return $this->set->count(); } } diff --git a/src/Transaction/Mutator/InputCollectionMutator.php b/src/Transaction/Mutator/InputCollectionMutator.php index 8832942d2..b571a3017 100644 --- a/src/Transaction/Mutator/InputCollectionMutator.php +++ b/src/Transaction/Mutator/InputCollectionMutator.php @@ -23,14 +23,6 @@ public function __construct(array $inputs) $this->set = \SplFixedArray::fromArray($set, false); } - /** - * @return InputMutator - */ - public function current(): InputMutator - { - return $this->set->current(); - } - /** * @param int $offset * @return InputMutator