Skip to content

Commit

Permalink
Feat/ra 71 wrong transaction size in operation metadata (#192)
Browse files Browse the repository at this point in the history
* feat: implement customstore to save TxSize

* feat: updated

* feat: added TxnEntity to api and added oneToone Entity mapping

* feat: readded txbody to dataitems

* refactor: removed unused code

* refactor: removed unused code

* refactor: mapstruct not needed

* chore: updated testDB

* chore: spotless and dependency clean up

* refactor: adding comments and extracting constants

* readding TransactionSizeEntity To yaciindexer to maintain the separation of both modules

* moved some classes

* moved some classes

* adjusted policyID for account test

* fixed codesmells

* adding support for PlutusV3

* refactor: refactored CustomTransactionSizeStore, added spotless

* refactor: refactored CustomTransactionSizeStore, added spotless

* refactor: refactored CustomTransactionSizeStore, added spotless

* node version update

* fix test

* delete empty file
  • Loading branch information
Kammerlo authored May 29, 2024
1 parent 4a324c2 commit e82232b
Show file tree
Hide file tree
Showing 26 changed files with 434 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .env.docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ CARDANO_NODE_HOST=cardano-node
# Service name in docker-compose or local cardano node
CARDANO_NODE_PORT=3001
# Uncomment if you are using local cardano node
CARDANO_NODE_VERSION=8.9.0
CARDANO_NODE_VERSION=8.9.3
CARDANO_NODE_SUBMIT_HOST=cardano-submit-api
NODE_SUBMIT_API_PORT=8090
CARDANO_NODE_SOCKET_PATH=/node
Expand Down
2 changes: 1 addition & 1 deletion .env.h2
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CARDANO_NODE_HOST=localhost
# Service name in docker-compose or local cardano node
CARDANO_NODE_PORT=3001
# Uncomment if you are using local cardano node
CARDANO_NODE_VERSION=8.9.0
CARDANO_NODE_VERSION=8.9.3
CARDANO_NODE_SUBMIT_HOST=localhost
NODE_SUBMIT_API_PORT=8090

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public interface BlockTxToEntity {
@Mapping(target = "hash", source = "txHash")
@Mapping(target = "blockHash", source = "block.hash")
@Mapping(target = "blockNo", source = "block.number")
@Mapping(target = "size", constant = "0L")
@Mapping(target = "scriptSize", constant = "0L")
@Mapping(target = "size", source = "sizeEntity.size")
@Mapping(target = "scriptSize", source = "sizeEntity.scriptSize")
@Mapping(target = "inputs", source = "inputKeys")
@Mapping(target = "outputs", source = "outputKeys")
BlockTx fromEntity(TxnEntity model);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.cardanofoundation.rosetta.api.block.model.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Getter
@Entity
@Table(name = "transaction_size")
public class TransactionSizeEntity {

@Column(name = "tx_hash")
@Id
private String txHash;

@Column(name = "block_number")
private long blockNumber;

@Column(name = "size")
private int size;

@Column(name = "script_size")
private int scriptSize;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;

import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -51,4 +52,10 @@ public class TxnEntity {

@OneToMany(mappedBy = "txHash")
private List<TxScriptEntity> script;

@OneToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "tx_hash",
foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT, name = "none"))
private TransactionSizeEntity sizeEntity;

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.cardanofoundation.rosetta.api.block.model.domain.Block;
import org.cardanofoundation.rosetta.api.block.model.domain.BlockTx;
import org.cardanofoundation.rosetta.api.block.model.entity.BlockEntity;
import org.cardanofoundation.rosetta.api.block.model.entity.TransactionSizeEntity;
import org.cardanofoundation.rosetta.api.block.model.entity.TxnEntity;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -88,6 +89,7 @@ private List<TxnEntity> newTxList() {
.block(BlockEntity.builder().hash("blockHash1").number(22L).build())
.fee(BigInteger.TEN)
.inputKeys(List.of())
.sizeEntity(new TransactionSizeEntity("txHash", 0L, 0, 0))
.outputKeys(List.of())
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.cardanofoundation.rosetta.api.BaseMapperSetup;
import org.cardanofoundation.rosetta.api.block.model.domain.BlockTx;
import org.cardanofoundation.rosetta.api.block.model.entity.BlockEntity;
import org.cardanofoundation.rosetta.api.block.model.entity.TransactionSizeEntity;
import org.cardanofoundation.rosetta.api.block.model.entity.TxnEntity;
import org.cardanofoundation.rosetta.api.block.model.entity.UtxoKey;

Expand Down Expand Up @@ -58,6 +59,7 @@ private TxnEntity newTxnEntity() {
.fee(BigInteger.TEN)
.inputKeys(List.of(inUtxKey))
.outputKeys(List.of(outUtxKey))
.sizeEntity(new TransactionSizeEntity("txHash", 0L, 0, 0))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void getBlockWithTransaction_Test() {

//then
assertEquals(simpleTx.blockHash(), block.getHash());
assertEquals(simpleTx.blockNumber(), block.getSlotNo());
assertEquals(simpleTx.blockNumber(), block.getNumber());
assertEquals(1, block.getTransactions().size());

Utxo receiverUtxoDto = block.getTransactions().getFirst().getOutputs().getFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ void findGenesisBlockIdentifier() {
private static void assertBlocks(Block latestBlock, BlockEntity fromBlockB) {
assertThat(latestBlock).isNotNull();
assertThat(latestBlock.getHash()).isEqualTo(fromBlockB.getHash());
assertThat(latestBlock.getSlotNo()).isEqualTo(fromBlockB.getNumber());
assertThat(latestBlock.getNumber()).isEqualTo(fromBlockB.getNumber());
assertThat(latestBlock.getTransactions()).hasSize(fromBlockB.getTransactions().size());
assertThat(latestBlock.getEpochNo()).isEqualTo(fromBlockB.getEpochNumber());
}
Expand All @@ -298,7 +298,7 @@ private static void assertBlockAndTx(Optional<Block> blockOpt, TransactionBlockD
var block = blockOpt.get();
assertThat(block).isNotNull();
assertThat(block.getHash()).isEqualTo(tx.blockHash());
assertThat(block.getSlotNo()).isEqualTo(tx.blockNumber());
assertThat(block.getNumber()).isEqualTo(tx.blockNumber());
assertThat(block.getTransactions()).hasSize(1);
assertThat(block.getTransactions().getFirst().getHash()).isEqualTo(tx.txHash());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void combineWithMetadataTest() throws IOException {
assertEquals(ADA, constructionMetadataResponse.getSuggestedFee().getFirst().getCurrency().getSymbol());
assertEquals(ADA_DECIMALS, constructionMetadataResponse.getSuggestedFee().getFirst().getCurrency().getDecimals());

assertEquals(BigDecimal.valueOf(146), constructionMetadataResponse.getMetadata().getTtl());
assertEquals(BigDecimal.valueOf(68), constructionMetadataResponse.getMetadata().getTtl());
assertEquals("4310", constructionMetadataResponse.getMetadata().getProtocolParameters().getCoinsPerUtxoSize());
assertEquals("2000000", constructionMetadataResponse.getMetadata().getProtocolParameters().getKeyDeposit());
assertEquals("500000000", constructionMetadataResponse.getMetadata().getProtocolParameters().getPoolDeposit());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void accountBalanceMintedTokenAndEmptyName_Test() {
accountBalanceResponse.getBalances().get(1).getValue());
assertNotEquals(accountBalanceResponse.getBalances().getFirst().getCurrency().getSymbol(),
accountBalanceResponse.getBalances().get(1).getCurrency().getSymbol());
assertEquals("", accountBalanceResponse.getBalances().get(1).getCurrency().getSymbol());
assertEquals("", accountBalanceResponse.getBalances().get(2).getCurrency().getSymbol());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

class AccountCoinsApiTest extends BaseSpringMvcSetup {

private final String myAssetPolicyId = "55fb0efbf5721e95a05c3d9a13fa63421c83689b35de6247d9d371ef";
private final String myAssetPolicyId = "7fb3df13910c057bd9254e847c076fb02de78503b9fa0ecdd70b566c";
private final String latestTxHashOnZeroSlot = generatedDataMap.get(
TestTransactionNames.SIMPLE_NEW_EMPTY_NAME_COINS_TRANSACTION.getName()).txHash() + ":0";
private final String expectedTestAccountCoinAmount = "1636394";
Expand Down
14 changes: 12 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@
<version.bloxbean>0.4.3</version.bloxbean>
<version.client-lib>0.5.1</version.client-lib>
<version.yaci>0.2.5</version.yaci>
<version.yaci-store>0.1.0-rc2-8071294-SNAPSHOT</version.yaci-store>
<version.yaci-store>0.1.0-rc2-323a1a4-SNAPSHOT</version.yaci-store>
<version.commons-io>2.11.0</version.commons-io>
<version.javax-validation-api>2.0.1.Final</version.javax-validation-api>
<version.bouncycastle>1.77</version.bouncycastle>
<version.spotless-maven-plugin>2.43.0</version.spotless-maven-plugin>
<version.bouncycastle>1.77</version.bouncycastle>
<version.spotbugs-maven-plugin>4.8.3.0</version.spotbugs-maven-plugin>
<version.findsecbugs-plugin>1.13.0</version.findsecbugs-plugin>
<version.assertj-core>3.25.3</version.assertj-core>
Expand Down Expand Up @@ -79,6 +79,16 @@
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
Expand Down
Binary file modified testData/devkit.db.mv.db
Binary file not shown.
48 changes: 24 additions & 24 deletions testData/testdata.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
{
"stake_key_deregistration" : {
"txHash" : "032ce4a519f2068703b0c78a00e8140f0f99de88e0b653750bf5d6f95b1c5ed2",
"blockHash" : "a52c5b82007bd87729fd81fb07867d44001eb3c7adaa888ced2eb783d84d6a7f",
"blockNumber" : 40
"blockHash" : "f9b9efb723ce51281cd7dbeb8ea22d405aa20b0be1678d71c60768aa9b1284fc",
"blockNumber" : 33
},
"pool_retirement" : {
"txHash" : "03b2264a382d87124b4f967fae166ff2ffc6cb0ce699f4b7812fdb81139f8264",
"blockHash" : "26c225eae5072eb057198d75d005f62eb0c139ec19ebd75c1969ef4d6b9aa0f0",
"blockNumber" : 52
"blockHash" : "9982166a157fa3ecad7bb597ac5941aea11de4f18b765642dab6f120acc99ec2",
"blockNumber" : 44
},
"simple_new_empty_name_coins_transaction" : {
"txHash" : "10f0251b21bb43910be3d85d239cabfd556ea4d7ad35445218df1537199fe3e9",
"blockHash" : "bb52b4a9720629a1bee84039697d1ae9759c08af9874872e2f83a465fa8eabaa",
"blockNumber" : 36
"txHash" : "e7d9a6e8e315a5bc60fd56afcfce38d07bde9ee6e27b2fe4f9c8b6ff9099c8c4",
"blockHash" : "602587bc0e908055fec5397cc6589d18671a282507942b833fdf674285e4b56e",
"blockNumber" : 28
},
"simple_second_lovelace_transaction" : {
"txHash" : "6dcbc6a6a5522970a06c85b7655eb3b766624efa90b539b4f39963da4197b719",
"blockHash" : "8cccb3ded3f1ef443463822d351a0c17e842fa5ad6894b58449a959613c1d3c2",
"blockNumber" : 32
"blockHash" : "9f00a0855efe6a8fb6b0f98b5594cfba2e7e071f43929ad48fe5bfe236b08331",
"blockNumber" : 24
},
"pool_delegation" : {
"txHash" : "f9636da9997361320db793dd6f9d7812ac186afadb28731bb3d57b3309d76ebd",
"blockHash" : "5ba2153151131ad27c9f9f5d375fd8a4d7949270eb6a979625d34693a90359e5",
"blockNumber" : 50
"blockHash" : "ed77ebe525228d3331fa98ce9eeb70eee7b32409e390ec6534afb9d64c8ee680",
"blockNumber" : 42
},
"simple_first_lovelace_transaction" : {
"txHash" : "97f5a0de75fe0a0098228765b44a09b15cee7142fcf97868817f594b51729553",
"blockHash" : "762f61a0fd5eb831c17b0a85b4fdcbf205cf9f654cdbb3321ce2d28802a21043",
"blockNumber" : 30
"blockHash" : "4828dcc220d6924ba280c4e41b7339a1e12606b7aaa0588cbccb3954497021fa",
"blockNumber" : 22
},
"simple_transaction_2" : {
"txHash" : "820999c1a9236cd0bf0c2d1f576d317049a5f54d205227ec308ec08cada54528",
"blockHash" : "3ee946df09e1f681a16fd3e1c30761116812a403d72f8d64ab21246debc6a7b1",
"blockNumber" : 42
"blockHash" : "9a530536f286245f2c9e2faff4c1364472172e84d3246a7591adc1a79c5e5260",
"blockNumber" : 35
},
"pool_registration" : {
"txHash" : "f0a4f95c9952b95570f33e0b6bfe71c262206945925c71115160b7070d878a4a",
"blockHash" : "4a08c8111269d5906d6943d9b23addd59a3e8a09d21b57e0d481b521c7a267f1",
"blockNumber" : 44
"blockHash" : "ee14291f2210865a241fbfe5e16570bff9d8240c363473d513f9ddfeb667b8da",
"blockNumber" : 37
},
"simple_new_coins_transaction" : {
"txHash" : "bd0a6deae9a2b9fffd2baa6bb819a928244ff67c0e2f563bb840f1d1e52746c0",
"blockHash" : "296623eb98dd9fe53abd0a756dd4d56ce7cca0254ac18e37b6220a5547254623",
"blockNumber" : 34
"txHash" : "ca3e467c8bc9aa2d5cb17576169cf66cd3694bf1f14682c3b94ad70e89498a06",
"blockHash" : "2c590cb5662aee6ec8e6282d99846df45f03b56c6f68b04c648e1e04ddf2b402",
"blockNumber" : 26
},
"stake_key_registration" : {
"txHash" : "d6d8ed0323bf594e692569d2d256ed1472e1c9e132552ef659452c9140191fec",
"blockHash" : "b557c2f3e6835adca0c0c631cc39e6408de37ef3b7588f0bd4db6e32cbd24880",
"blockNumber" : 38
"blockHash" : "eec3a4ec9358b425068d942c20a4a73f020e36e6cf958fa1dc9d17d1f10aff8b",
"blockNumber" : 31
},
"simple_transaction" : {
"txHash" : "6a8ace2755a79bd239f43b7562cb80a11c062c5ec5ed9418da6553c89c5405b3",
"blockHash" : "468ee0b29874c71909c86d054c97580c72bbe29321c306047930f119abe19519",
"blockNumber" : 28
"blockHash" : "65067e5651bd8b3051463ab46464f2c45cda8b3669aa2cf69f5d2297d613d4f4",
"blockNumber" : 20
}
}
32 changes: 32 additions & 0 deletions yaci-indexer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<properties>
<java.version>21</java.version>
<yaci-store.version>0.1.0-rc2-323a1a4-SNAPSHOT</yaci-store.version>
<sonar.exclusions>src/main/java/org/cardanofoundation/rosetta/yaciindexer/stores/txsize/model/*</sonar.exclusions>
<version.spotless-maven-plugin>2.43.0</version.spotless-maven-plugin>
</properties>
<repositories>
<repository>
Expand Down Expand Up @@ -99,6 +101,36 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>${version.spotless-maven-plugin}</version>
<configuration>
<java>
<excludes>
<exclude>target/**/*.java</exclude>
</excludes>
<replaceRegex>
<name>Remove wildcard imports</name>
<searchRegex>import\\s+[^\\*\\s]+\\*;(\\r\\n|\\r|\\n)</searchRegex>
<replacement>$1</replacement>
</replaceRegex>
<removeUnusedImports/>
<importOrder>
<order>
java|jakarta|javax,lombok,org.springframework|, ,org.junit,org.cardanofoundation,\#
</order>
</importOrder>
<trimTrailingWhitespace/>
<indent>
<spaces>true</spaces>
<spacesPerTab>2</spacesPerTab>
</indent>
<trimTrailingWhitespace/>
<endWithNewline/>
</java>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import com.bloxbean.cardano.yaci.core.config.YaciConfig;

@SpringBootApplication
@Import(ConfigurationH2.class)
@EntityScan({
"org.cardanofoundation.rosetta.yaciindexer.stores.txsize.model"
})
@EnableJpaRepositories({
"org.cardanofoundation.rosetta.yaciindexer.stores.txsize.model"
})
public class YaciIndexerApplication {

public static void main(String[] args) {
YaciConfig.INSTANCE.setReturnBlockCbor(true);
YaciConfig.INSTANCE.setReturnTxBodyCbor(true);
SpringApplication.run(YaciIndexerApplication.class, args);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.cardanofoundation.rosetta.yaciindexer.mapper;

import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import com.bloxbean.cardano.yaci.store.blocks.domain.Block;
import com.bloxbean.cardano.yaci.store.blocks.storage.impl.mapper.BlockMapperImpl;
import com.bloxbean.cardano.yaci.store.blocks.storage.impl.model.BlockEntity;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

@Component
@Primary
Expand All @@ -24,4 +24,4 @@ public BlockEntity toBlockEntity(Block blockDetails) {
.slotLeader(blockDetails.getSlotLeader())
.build();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.cardanofoundation.rosetta.yaciindexer.mapper;

import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import com.bloxbean.cardano.yaci.store.staking.domain.PoolRegistration;
import com.bloxbean.cardano.yaci.store.staking.domain.PoolRetirement;
import com.bloxbean.cardano.yaci.store.staking.storage.impl.mapper.PoolMapperImpl;
import com.bloxbean.cardano.yaci.store.staking.storage.impl.model.PoolRegistrationEnity;
import com.bloxbean.cardano.yaci.store.staking.storage.impl.model.PoolRetirementEntity;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

@Component
@Primary
Expand Down
Loading

0 comments on commit e82232b

Please sign in to comment.