Skip to content

Commit 0225cfe

Browse files
Merge pull request #9 from Bitcoin-com/0.0.3-SNAPSHOT
0.0.3 snapshot
2 parents 1709fd3 + 64c05e1 commit 0225cfe

File tree

13 files changed

+103
-104
lines changed

13 files changed

+103
-104
lines changed

slp-indexer-api-service/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.bitcoin.indexer</groupId>
77
<artifactId>slp-indexer-api-service</artifactId>
8-
<version>0.0.2</version>
8+
<version>0.0.3</version>
99
<packaging>pom</packaging>
1010

1111
<name>API</name>
@@ -36,17 +36,17 @@
3636
<dependency>
3737
<groupId>com.bitcoin.indexer</groupId>
3838
<artifactId>slp-indexer-api-service-domain</artifactId>
39-
<version>0.0.2</version>
39+
<version>0.0.3</version>
4040
</dependency>
4141
<dependency>
4242
<groupId>com.bitcoin.indexer</groupId>
4343
<artifactId>slp-indexer-api-service-app</artifactId>
44-
<version>0.0.2</version>
44+
<version>0.0.3</version>
4545
</dependency>
4646
<dependency>
4747
<groupId>com.bitcoin.indexer</groupId>
4848
<artifactId>slp-indexer-api-service-integration-test</artifactId>
49-
<version>0.0.2</version>
49+
<version>0.0.3</version>
5050
</dependency>
5151

5252
<dependency>

slp-indexer-api-service/slp-indexer-api-service-app/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<parent>
99
<groupId>com.bitcoin.indexer</groupId>
1010
<artifactId>slp-indexer-api-service</artifactId>
11-
<version>0.0.2</version>
11+
<version>0.0.3</version>
1212
</parent>
1313

1414
<artifactId>slp-indexer-api-service-app</artifactId>
15-
<version>0.0.2</version>
15+
<version>0.0.3</version>
1616

1717
<dependencies>
1818
<dependency>
@@ -35,7 +35,7 @@
3535
<dependency>
3636
<groupId>com.bitcoin.indexer</groupId>
3737
<artifactId>slp-indexer-service-domain</artifactId>
38-
<version>0.0.2</version>
38+
<version>0.0.3</version>
3939
</dependency>
4040

4141
<dependency>

slp-indexer-api-service/slp-indexer-api-service-domain/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<parent>
99
<groupId>com.bitcoin.indexer</groupId>
1010
<artifactId>slp-indexer-api-service</artifactId>
11-
<version>0.0.2</version>
11+
<version>0.0.3</version>
1212
</parent>
1313

1414
<artifactId>slp-indexer-api-service-domain</artifactId>
15-
<version>0.0.2</version>
15+
<version>0.0.3</version>
1616

1717
<dependencies>
1818
<dependency>

slp-indexer-api-service/slp-indexer-api-service-integration-test/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<parent>
99
<groupId>com.bitcoin.indexer</groupId>
1010
<artifactId>slp-indexer-api-service</artifactId>
11-
<version>0.0.2</version>
11+
<version>0.0.3</version>
1212
</parent>
1313

1414
<artifactId>slp-indexer-api-service-integration-test</artifactId>
15-
<version>0.0.2</version>
15+
<version>0.0.3</version>
1616

1717
<dependencies>
1818
<dependency>

slp-indexer-service/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.bitcoin.indexer</groupId>
77
<artifactId>slp-indexer-service</artifactId>
8-
<version>0.0.2</version>
8+
<version>0.0.3</version>
99
<packaging>pom</packaging>
1010

1111
<name>WRITER</name>

slp-indexer-service/slp-indexer-service-app/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<parent>
99
<groupId>com.bitcoin.indexer</groupId>
1010
<artifactId>slp-indexer-service</artifactId>
11-
<version>0.0.2</version>
11+
<version>0.0.3</version>
1212
</parent>
1313

1414
<artifactId>slp-indexer-service-app</artifactId>
15-
<version>0.0.2</version>
15+
<version>0.0.3</version>
1616

1717
<dependencies>
1818
<dependency>

slp-indexer-service/slp-indexer-service-app/src/main/java/com/bitcoin/indexer/facade/validators/GenesisValidatorAssumeParentValid.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ public SlpValid isValid(String txId, String tokenId, String tokenType, List<Utxo
6767
if (onlySlpUtxo(utxos)
6868
.anyMatch(SlpUtxo::isGenesis)) {
6969

70+
if (utxoFromPrev.getSlpUtxo().get().getTokenType().equals(SlpTokenType.NFT1_GENESIS.getType()) && inputs.size() > 1) {
71+
if (tokenType.equals(SlpTokenType.NFT1_CHILD.getType())) {
72+
if (onlySlpUtxo(utxos).anyMatch(slpUtxo -> slpUtxo.getAmount().compareTo(BigDecimal.ONE) == 0)) {
73+
return SlpValid.invalid("NFT1 parent GENESIS tx, the NFT1 child GENESIS tx w/ qty=1 should be SLP-invalid");
74+
}
75+
}
76+
}
77+
7078
if (onlySlpUtxo(utxos)
7179
.map(SlpUtxo::getAmount).reduce(BigDecimal::add).orElse(BigDecimal.ZERO).equals(BigDecimal.ONE)) {
7280
return SlpValid.valid("prev is genesis and current has amount == 1");

slp-indexer-service/slp-indexer-service-domain/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
<parent>
1313
<groupId>com.bitcoin.indexer</groupId>
1414
<artifactId>slp-indexer-service</artifactId>
15-
<version>0.0.2</version>
15+
<version>0.0.3</version>
1616
</parent>
1717

1818
<artifactId>slp-indexer-service-domain</artifactId>
19-
<version>0.0.2</version>
19+
<version>0.0.3</version>
2020

2121

2222
<dependencies>

slp-indexer-service/slp-indexer-service-domain/src/main/java/com/bitcoin/indexer/blockchain/domain/slp/SlpOpReturnGenesis.kt

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,56 @@ data class SlpOpReturnGenesis(
2828
validateChunkSize(chunks)
2929
val ticker = chunks[4]?.let { String(it).replace(Char.MIN_VALUE, ' ') } ?: ""
3030
val name = chunks[5]?.let { String(it).replace(Char.MIN_VALUE, ' ') } ?: ""
31-
val decimals = chunks[8]?.let { ByteUtils.toInt(validateDecimals(it)) } ?: return null
32-
val batonByte: Byte? = validateBatonVout(chunks[9]?.getOrNull(0))
33-
val mintedAmount = chunks[10]?.let { it }.let { UnsignedBigInteger.parseUnsigned(BigInteger(it)) } ?: return null
31+
val decimals = chunks[8]?.let { ByteUtils.toInt(validateDecimals(it, tokenType)) } ?: return null
32+
val batonByte: Byte? = validateBatonVout(chunks[9]?.getOrNull(0), tokenType)
33+
val mintedAmount = validateNFTAmount(UnsignedBigInteger.parseUnsigned(BigInteger(chunks[10]?.let { it })), tokenType) ?: return null
3434
val documentUri = chunks[6]?.let { String(it).replace(Char.MIN_VALUE, '0') } ?: ""
3535
val documentHash = chunks[7]?.let { String(validateDocumentHash(it)).replace(Char.MIN_VALUE, '0') } ?: ""
3636
return SlpOpReturnGenesis(tokenType, tokenId, ticker, name, decimals, batonByte?.toInt(), mintedAmount, documentUri);
3737
}
3838

39-
private fun validateDecimals(chunk: ByteArray): ByteArray {
39+
private fun validateDecimals(chunk: ByteArray, tokenType: SlpTokenType): ByteArray {
4040
if (chunk.isEmpty() || chunk.size > 1) {
4141
throw RuntimeException("Invalid decimals")
4242
}
4343
if (ByteUtils.toInt(chunk) > 9) {
4444
throw RuntimeException("Invalid decimals")
4545
}
4646

47+
if (ByteUtils.toInt(tokenType.bytes) == ByteUtils.toInt(byteArrayOf(0x41))) {
48+
if (ByteUtils.toInt(chunk) != 0) {
49+
throw RuntimeException("Invalid decimals")
50+
}
51+
}
52+
4753
return chunk;
4854
}
4955

50-
private fun validateBatonVout(batonByte: Byte?): Byte? {
56+
private fun validateBatonVout(batonByte: Byte?, tokenType: SlpTokenType): Byte? {
5157
if (batonByte != null) {
5258
if (batonByte.toInt() == 0 || batonByte.toInt() == 1) {
5359
throw RuntimeException("Invalid baton")
5460
}
5561
}
62+
63+
if (ByteUtils.toInt(tokenType.bytes) == ByteUtils.toInt(byteArrayOf(0x41))) {
64+
if (batonByte != null) {
65+
throw RuntimeException("Invalid baton")
66+
}
67+
}
68+
5669
return batonByte
5770
}
5871

72+
private fun validateNFTAmount(value: BigInteger, tokenType: SlpTokenType): BigInteger {
73+
if (ByteUtils.toInt(tokenType.bytes) == ByteUtils.toInt(byteArrayOf(0x41))) {
74+
if (value.compareTo(BigInteger.ONE) != 0) {
75+
throw RuntimeException("NFT cannot have larger quantity than 1")
76+
}
77+
}
78+
return value;
79+
}
80+
5981
private fun validateDocumentHash(chunk: ByteArray): ByteArray {
6082
if (chunk.size == 32 || chunk.isEmpty()) {
6183
return chunk
@@ -71,8 +93,6 @@ data class SlpOpReturnGenesis(
7193
}
7294

7395

74-
75-
7696
override fun toString(): String {
7797
return "SlpOpReturnGenesis(tokenType=$tokenType, tokenId=$tokenId, ticker='$ticker', name='$name', decimals=$decimals, batonVout=$batonVout, mintedAmount=$mintedAmount, documentUri='$documentUri')"
7898
}

slp-indexer-service/slp-indexer-service-domain/src/main/java/com/bitcoin/indexer/blockchain/domain/slp/SlpTokenType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public class SlpTokenType {
99
private final String type;
1010
private final byte[] bytes;
1111

12-
public static final SlpTokenType PERMISSIONLESS = new SlpTokenType("PERMISSIONLESS", String.valueOf(1).getBytes());
13-
public static final SlpTokenType NFT1_GENESIS = new SlpTokenType("NFT1_GENESIS", String.valueOf(129).getBytes());
14-
public static final SlpTokenType NFT1_CHILD = new SlpTokenType("NFT1_CHILD", String.valueOf(65).getBytes());
12+
public static final SlpTokenType PERMISSIONLESS = new SlpTokenType("PERMISSIONLESS", new byte[]{0x01});
13+
public static final SlpTokenType NFT1_GENESIS = new SlpTokenType("NFT1_GENESIS", new byte[]{ (byte) 0x81 });
14+
public static final SlpTokenType NFT1_CHILD = new SlpTokenType("NFT1_CHILD", new byte[]{0x41});
1515

1616
private static final Map<Integer, String> currentKnownTokens =
1717
Map.of(1, "PERMISSIONLESS",

0 commit comments

Comments
 (0)