Skip to content

Commit 162a95e

Browse files
committed
return output type
1 parent ac60520 commit 162a95e

File tree

9 files changed

+69
-1
lines changed

9 files changed

+69
-1
lines changed

src/Output/OutputInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
interface OutputInterface
1515
{
16+
/**
17+
* @return string
18+
*/
19+
public function type(): string;
20+
1621
/**
1722
* @return string
1823
*/

src/Output/Outputs/P2ms.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ public function getPubKeys(): array
7474
return $this->pubKeys;
7575
}
7676

77+
/**
78+
* @return string
79+
*/
80+
public function type(): string
81+
{
82+
return 'p2ms';
83+
}
84+
7785
/**
7886
* @return string
7987
*/

src/Output/Outputs/P2pk.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ public function getPubKey(): string
4545
return $this->pubKey;
4646
}
4747

48+
/**
49+
* @return string
50+
*/
51+
public function type(): string
52+
{
53+
return 'p2pk';
54+
}
55+
4856
/**
4957
* @return string
5058
*/

src/Output/Outputs/P2pkh.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public function getPubKeyHash(): string
4343
return $this->pubKeyHash;
4444
}
4545

46+
/**
47+
* @return string
48+
*/
49+
public function type(): string
50+
{
51+
return 'p2pkh';
52+
}
53+
4654
/**
4755
* @return string
4856
*/

src/Output/Outputs/P2sh.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public function getScriptHash(): string
4747
return $this->scriptHash;
4848
}
4949

50+
/**
51+
* @return string
52+
*/
53+
public function type(): string
54+
{
55+
return 'p2sh';
56+
}
57+
5058
/**
5159
* @return string
5260
*/

src/Output/Outputs/P2tr.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public function getTaprootPubKey(): string
4141
return $this->taprootPubKey;
4242
}
4343

44+
/**
45+
* @return string
46+
*/
47+
public function type(): string
48+
{
49+
return 'p2tr';
50+
}
51+
4452
/**
4553
* @return string
4654
*/

src/Output/Outputs/P2wpkh.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ public function getPubKeyHash(): string
4343
return $this->pubKeyHash;
4444
}
4545

46+
/**
47+
* @return string
48+
*/
49+
public function type(): string
50+
{
51+
return 'p2wpkh';
52+
}
53+
4654
/**
4755
* @return string
4856
*/

src/Output/Outputs/P2wsh.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,15 @@ public function getWitnessHash(): string
4646
{
4747
return $this->witnessHash;
4848
}
49-
49+
50+
/**
51+
* @return string
52+
*/
53+
public function type(): string
54+
{
55+
return 'p2wsh';
56+
}
57+
5058
/**
5159
* @return string
5260
*/

tests/OutputFactoryTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public function testFromHexP2PK()
2929
$output = OutputFactory::fromHex('210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac');
3030
$this->assertInstanceOf(P2pk::class, $output);
3131
$this->assertEquals($output->getPubKey(), hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'));
32+
$this->assertEquals($output->type(), 'p2pk');
3233
}
3334

3435
/**
@@ -39,6 +40,7 @@ public function testFromHexP2PKH()
3940
$output = OutputFactory::fromHex('76a914751e76e8199196d454941c45d1b3a323f1433bd688ac');
4041
$this->assertInstanceOf(P2pkh::class, $output);
4142
$this->assertEquals($output->getPubKeyHash(), hex2bin('751e76e8199196d454941c45d1b3a323f1433bd6'));
43+
$this->assertEquals($output->type(), 'p2pkh');
4244
}
4345

4446
/**
@@ -50,6 +52,7 @@ public function testFromHexP2MS()
5052
$this->assertInstanceOf(P2ms::class, $output);
5153
$this->assertEquals($output->getPubKeys(), [hex2bin('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798')]);
5254
$this->assertEquals($output->getSigCount(), 1);
55+
$this->assertEquals($output->type(), 'p2ms');
5356
}
5457

5558
/**
@@ -60,6 +63,7 @@ public function testFromHexP2SH()
6063
$output = OutputFactory::fromHex('a91483eebb7d79aa1d388e3b0ac65b98ac580c4da01a87');
6164
$this->assertInstanceOf(P2sh::class, $output);
6265
$this->assertEquals($output->getScriptHash(), hex2bin('83eebb7d79aa1d388e3b0ac65b98ac580c4da01a'));
66+
$this->assertEquals($output->type(), 'p2sh');
6367
}
6468

6569
/**
@@ -70,6 +74,7 @@ public function testFromHexP2WPKH()
7074
$output = OutputFactory::fromHex('0014751e76e8199196d454941c45d1b3a323f1433bd6');
7175
$this->assertInstanceOf(P2wpkh::class, $output);
7276
$this->assertEquals($output->getPubKeyHash(), hex2bin('751e76e8199196d454941c45d1b3a323f1433bd6'));
77+
$this->assertEquals($output->type(), 'p2wpkh');
7378
}
7479

7580
/**
@@ -80,6 +85,7 @@ public function testFromHexP2WSH()
8085
$output = OutputFactory::fromHex('002028205333db922f66e8a941b4a32d66de5cea03d9cda46e3e6658935272b9b24f');
8186
$this->assertInstanceOf(P2wsh::class, $output);
8287
$this->assertEquals($output->getWitnessHash(), hex2bin('28205333db922f66e8a941b4a32d66de5cea03d9cda46e3e6658935272b9b24f'));
88+
$this->assertEquals($output->type(), 'p2wsh');
8389
}
8490

8591
/**
@@ -90,5 +96,6 @@ public function testFromHexP2TR()
9096
$output = OutputFactory::fromHex('5120a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c');
9197
$this->assertInstanceOf(P2tr::class, $output);
9298
$this->assertEquals($output->getTaprootPubKey(), hex2bin('a60869f0dbcf1dc659c9cecbaf8050135ea9e8cdc487053f1dc6880949dc684c'));
99+
$this->assertEquals($output->type(), 'p2tr');
93100
}
94101
}

0 commit comments

Comments
 (0)