Skip to content

Commit

Permalink
Explore core migrated #322
Browse files Browse the repository at this point in the history
  • Loading branch information
straumat committed Nov 9, 2023
1 parent f977fb3 commit dd91063
Show file tree
Hide file tree
Showing 32 changed files with 275 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import org.royllo.explorer.core.dto.user.UserDTO;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

import static lombok.AccessLevel.PRIVATE;
Expand Down Expand Up @@ -84,7 +83,7 @@ public class AssetStateDTO {
String leaseOwner;

/** If the asset has been leased, this is the expiry of the lease as a Unix timestamp in seconds. */
long leaseExpiry;
Long leaseExpiry;

/** The merkle proof for AnchorTx used to prove its inclusion within BlockHeader. */
String txMerkleProof;
Expand All @@ -93,13 +92,13 @@ public class AssetStateDTO {
String inclusionProof;

/** The set of TaprootProofs proving the exclusion of the resulting asset from all other Taproot outputs within AnchorTx. */
List<String> exclusionProofs = new ArrayList<>();
List<String> exclusionProofs;

/** An optional TaprootProof needed if this asset is the result of a split. SplitRootProof proves inclusion of the root asset of the split. */
String splitRootProof;

/** ChallengeWitness is an optional virtual transaction witness that serves as an ownership proof for the asset. */
List<String> challengeWitness = new ArrayList<>();
List<String> challengeWitness;

/** The asset state ID that uniquely identifies the asset state (calculated by Royllo). */
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ public static class DecodedProof {
@JsonProperty("exclusion_proofs")
List<String> exclusionProofs;

/** An optional TaprootProof needed if this asset is the result of a split. SplitRootProof proves inclusion of the root asset of the split. */
@JsonProperty("split_root_proof")
String splitRootProof;

/** The number of additional nested full proofs for any inputs found within the resulting asset. */
@JsonProperty("num_additional_inputs")
long numberOfAdditionalInputs;

/** ChallengeWitness is an optional virtual transaction witness that serves as an ownership proof for the asset. */
@JsonProperty("challenge_witness")
List<String> challengeWitness;

/** Indicates whether the state transition this proof represents is a burn, meaning that the assets were provably destroyed and can no longer be spent. */
@JsonProperty("is_burn")
Boolean isBurn;

@Getter
@Setter
@NoArgsConstructor
Expand Down Expand Up @@ -115,6 +131,39 @@ public static class Asset {
@JsonProperty("prev_witnesses")
List<String> prevWitnesses;

/** Indicates whether the asset has been spent. */
@JsonProperty("is_spent")
Boolean isSpent;

/** If the asset has been leased, this is the owner (application ID) of the lease. */
@JsonProperty("lease_owner")
String leaseOwner;

/** If the asset has been leased, this is the expiry of the lease as a Unix timestamp in seconds. */
@JsonProperty("lease_expiry")
String leaseExpiry;

/** Indicates whether this transfer was an asset burn. If true, the number of assets in this output are destroyed and can no longer be spent. */
@JsonProperty("is_burn")
Boolean isBurn;

/**
* If the asset has been leased, this is the expiry of the lease as a Unix timestamp in seconds.
*
* @return lease expiry timestamp
*/
public final Long getLeaseExpiryTimestamp() {
if (leaseExpiry == null) {
return 0L;
} else {
try {
return Long.parseLong(leaseExpiry);
} catch (NumberFormatException e) {
return 0L;
}
}
}

@Getter
@Setter
@NoArgsConstructor
Expand Down Expand Up @@ -204,6 +253,10 @@ public static class ChainAnchor {
@JsonProperty("tapscript_sibling")
String tapscriptSibling;

/** Block height. */
@JsonProperty("block_height")
long blockHeight;

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public String convertToDatabaseColumn(final List<String> stringList) {

@Override
public List<String> convertToEntityAttribute(final String string) {
if (string != null) {
if (string != null && !string.isEmpty()) {
return Arrays.asList(string.split(SPLIT_CHAR));
} else {
return emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,29 @@ public interface AssetStateMapper {
@Mapping(target = "creator", ignore = true)
@Mapping(target = "assetStateId", ignore = true)
@Mapping(source = ".", target = "asset")
@Mapping(source = "asset.chainAnchor.anchorTx", target = "anchorTx")
@Mapping(source = "asset.chainAnchor.anchorBlockHash", target = "anchorBlockHash")
@Mapping(source = "asset.chainAnchor.anchorOutpoint", target = "anchorOutpoint")
@Mapping(source = "asset.chainAnchor.anchorTx", target = "anchorTx")
@Mapping(source = "asset.chainAnchor.internalKey", target = "internalKey")
@Mapping(source = "asset.chainAnchor.merkleRoot", target = "merkleRoot")
@Mapping(source = "asset.chainAnchor.tapscriptSibling", target = "tapscriptSibling")

@Mapping(source = "asset.version", target = "version")
@Mapping(source = "asset.amount", target = "amount")
@Mapping(source = "asset.lockTime", target = "lockTime")
@Mapping(source = "asset.relativeLockTime", target = "relativeLockTime")

@Mapping(source = "asset.scriptVersion", target = "scriptVersion")
@Mapping(source = "asset.scriptKey", target = "scriptKey")

@Mapping(source = "asset.leaseOwner", target = "leaseOwner")
@Mapping(source = "asset.leaseExpiryTimestamp", target = "leaseExpiry")

@Mapping(source = "txMerkleProof", target = "txMerkleProof")
@Mapping(source = "inclusionProof", target = "inclusionProof")
@Mapping(source = "exclusionProofs", target = "exclusionProofs")
@Mapping(source = "splitRootProof", target = "splitRootProof")
@Mapping(source = "challengeWitness", target = "challengeWitness")
AssetStateDTO mapToAssetStateDTO(DecodedProofResponse.DecodedProof source);

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
<column name="SCRIPT_KEY" value="025d615b377761a5bfcfe84f0f11afd35837a68f702dd8a0cac0a2a4052b20d211"/>

<column name="LEASE_OWNER" value=""/>
<column name="LEASE_OWNER" value="0"/>
<column name="LEASE_EXPIRY" value="0"/>

<column name="TX_MERKLE_ROOT"
<column name="TX_MERKLE_PROOF"
value="060d6cca264dc5ae7811f5e30305b64021c4b6107325359dd2964afb464ede9d209af1a7478aa5e8704ed521214bfa5935f022a3282ca01ec378743f8f2b26e883d7c81784fdd7aa621d14239510ee5f06add858f8f7c262941b6642674650628793c0b475e851828cbbd4048d003279eb3617939dee343f2a0edc55c6eb694929ac0f81acc5d39a6dd1675e351a7c26c84a6636253d30525ed7f09e9aba7d472b9d9a0a166581b27a343859332d3bebc60736a221995481b9355a475bb52c468330"/>
<column name="INCLUSION_PROOF"
value="0004000000000221026ad322cc8a05cf5723bf8aeb5c778c6462146e573af182ba20c6bed53ea29ae6037401490001000220ce5a426ea282d2dee3a2eb48170231403ee4768be17f73fef8e6f925d30797af04220000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff022700010002220000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
remarks="If the asset has been leased, this is the owner (application ID) of the lease"/>
<column name="LEASE_EXPIRY" type="BIGINT"
remarks="If the asset has been leased, this is the expiry of the lease as a Unix timestamp in seconds."/>
<column name="TX_MERKLE_ROOT" type="TEXT"
<column name="TX_MERKLE_PROOF" type="TEXT"
remarks="The merkle root of the transaction that created the asset"/>
<column name="INCLUSION_PROOF" type="TEXT"
remarks="The TaprootProof proving the new inclusion of the resulting asset within AnchorTx"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void addAssetGroup() {
// =============================================================================================================
// Constraint test - Asset group key already registered.
e = assertThrows(AssertionError.class, () -> assetGroupService.addAssetGroup(AssetGroupDTO.builder()
.assetGroupId(UNLIMITED_ROYLLO_COIN_1_FROM_TEST.getDecodedProof(0).getAsset().getAssetGroup().getTweakedGroupKey())
.assetGroupId(UNLIMITED_ROYLLO_COIN_1_FROM_TEST.getDecodedProofResponse(0).getAsset().getAssetGroup().getTweakedGroupKey())
.tweakedGroupKey("TWEAKED_GROUP_KEY_10000").build()));
assertEquals("Asset group id already registered", e.getMessage());

Expand Down Expand Up @@ -80,13 +80,13 @@ public void getAssetGroupByAssetGroupId() {

// =============================================================================================================
// Existing asset group on testnet and in our database initialization script.
assetGroup = assetGroupService.getAssetGroupByAssetGroupId(UNLIMITED_ROYLLO_COIN_1_FROM_TEST.getDecodedProof(0).getAsset().getAssetGroup().getTweakedGroupKey());
assetGroup = assetGroupService.getAssetGroupByAssetGroupId(UNLIMITED_ROYLLO_COIN_1_FROM_TEST.getDecodedProofResponse(0).getAsset().getAssetGroup().getTweakedGroupKey());
assertTrue(assetGroup.isPresent());
assertNotNull(assetGroup.get().getId());
assertEquals(UNLIMITED_ROYLLO_COIN_1_FROM_TEST.getDecodedProof(0).getAsset().getAssetGroup().getTweakedGroupKey(), assetGroup.get().getAssetGroupId());
assertEquals(UNLIMITED_ROYLLO_COIN_1_FROM_TEST.getDecodedProof(0).getAsset().getAssetGroup().getRawGroupKey(), assetGroup.get().getRawGroupKey());
assertEquals(UNLIMITED_ROYLLO_COIN_1_FROM_TEST.getDecodedProof(0).getAsset().getAssetGroup().getTweakedGroupKey(), assetGroup.get().getTweakedGroupKey());
assertEquals(UNLIMITED_ROYLLO_COIN_1_FROM_TEST.getDecodedProof(0).getAsset().getAssetGroup().getAssetWitness(), assetGroup.get().getAssetWitness());
assertEquals(UNLIMITED_ROYLLO_COIN_1_FROM_TEST.getDecodedProofResponse(0).getAsset().getAssetGroup().getTweakedGroupKey(), assetGroup.get().getAssetGroupId());
assertEquals(UNLIMITED_ROYLLO_COIN_1_FROM_TEST.getDecodedProofResponse(0).getAsset().getAssetGroup().getRawGroupKey(), assetGroup.get().getRawGroupKey());
assertEquals(UNLIMITED_ROYLLO_COIN_1_FROM_TEST.getDecodedProofResponse(0).getAsset().getAssetGroup().getTweakedGroupKey(), assetGroup.get().getTweakedGroupKey());
assertEquals(UNLIMITED_ROYLLO_COIN_1_FROM_TEST.getDecodedProofResponse(0).getAsset().getAssetGroup().getAssetWitness(), assetGroup.get().getAssetWitness());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void queryAssets() {
assertEquals(0, results.getTotalPages());

// Searching for an asset with its group asset id
results = assetService.queryAssets(SET_OF_ROYLLO_NFT_1_FROM_TEST.getDecodedProof(0).getAsset().getAssetGroup().getTweakedGroupKey(), 1, 5);
results = assetService.queryAssets(SET_OF_ROYLLO_NFT_1_FROM_TEST.getDecodedProofResponse(0).getAsset().getAssetGroup().getTweakedGroupKey(), 1, 5);
assertEquals(3, results.getTotalElements());
assertEquals(1, results.getTotalPages());
assertEquals(SET_OF_ROYLLO_NFT_1_ASSET_ID, results.getContent().get(0).getAssetId());
Expand Down Expand Up @@ -369,7 +369,7 @@ public void getAssetsByAssetGroupId() {
assertEquals(0, assetService.getAssetsByAssetGroupId("NON_EXISTING_ASSET_GROUP_ID").size());

// Test with an asset group with three assets.
final String tweakedGroupKey = SET_OF_ROYLLO_NFT_1_FROM_TEST.getDecodedProof(0).getAsset().getAssetGroup().getTweakedGroupKey();
final String tweakedGroupKey = SET_OF_ROYLLO_NFT_1_FROM_TEST.getDecodedProofResponse(0).getAsset().getAssetGroup().getTweakedGroupKey();
assertEquals(3, assetService.getAssetsByAssetGroupId(tweakedGroupKey).size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.royllo.explorer.core.util.constants.UserConstants.ANONYMOUS_ID;
import static org.royllo.explorer.core.util.constants.UserConstants.ANONYMOUS_USER_DTO;
import static org.royllo.explorer.core.util.constants.UserConstants.ANONYMOUS_USER_ID;
import static org.royllo.test.MempoolData.ROYLLO_COIN_ANCHOR_1_TXID;
Expand Down Expand Up @@ -226,13 +227,13 @@ public void getAssetStateByAssetStateId() {

// =============================================================================================================
// Existing asset state on testnet and in our database initialization script ("roylloCoin").
assetState = assetStateService.getAssetStateByAssetStateId(ROYLLO_COIN_FROM_TEST.getDecodedProof(0).getAsset().getAssetStateId());
assetState = assetStateService.getAssetStateByAssetStateId(ROYLLO_COIN_FROM_TEST.getDecodedProofResponse(0).getAsset().getAssetStateId());
assertTrue(assetState.isPresent());
assertEquals(1, assetState.get().getId());
assertEquals(ROYLLO_COIN_FROM_TEST.getDecodedProof(0).getAsset().getAssetStateId(), assetState.get().getAssetStateId());
assertEquals(ROYLLO_COIN_FROM_TEST.getDecodedProofResponse(0).getAsset().getAssetStateId(), assetState.get().getAssetStateId());
// User.
assertNotNull(assetState.get().getCreator());
assertEquals(ANONYMOUS_USER_DTO.getId(), assetState.get().getCreator().getId());
assertEquals(ANONYMOUS_ID, assetState.get().getCreator().getId());
// Asset & asset group.
verifyAsset(assetState.get().getAsset(), ROYLLO_COIN_ASSET_ID);
// Asset state data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ SELECT count(*) as USER_COUNT

@Test
@DisplayName("LTree found in pg_extension")
public void treeFoundInPGExtension() throws SQLException {
public void lTreeFoundInPGExtension() throws SQLException {
try (Connection connection = dataSource.getConnection()) {
final ResultSet results = connection.createStatement()
.executeQuery("""
Expand Down
Loading

0 comments on commit dd91063

Please sign in to comment.