Skip to content

Commit

Permalink
feat: add authorSubmitExtrinsic implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgi Grigorov committed Nov 12, 2024
1 parent ab6127d commit 7b7bf5d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/limechain/rpc/methods/RPCMethodsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,12 @@ public Boolean authorHasSessionKeys(String sessionKeys) {

@Override
public String authorSubmitExtrinsic(String extrinsics) {
return "";
return authorRPC.authorSubmitExtrinsic(extrinsics);
}

@Override
public String authorSubmitAndWatchExtrinsic(String extrinsics) {
return "";
return authorRPC.authorSubmitAndWatchExtrinsic(extrinsics);
}
//endregion
}
29 changes: 26 additions & 3 deletions src/main/java/com/limechain/rpc/methods/author/AuthorRPCImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

import com.limechain.exception.global.ExecutionFailedException;
import com.limechain.exception.storage.BlockStorageGenericException;
import com.limechain.exception.transaction.TransactionValidationException;
import com.limechain.rpc.methods.author.dto.DecodedKey;
import com.limechain.runtime.Runtime;
import com.limechain.storage.block.BlockState;
import com.limechain.storage.crypto.KeyStore;
import com.limechain.storage.crypto.KeyType;
import com.limechain.transaction.TransactionState;
import com.limechain.transaction.TransactionValidator;
import com.limechain.transaction.dto.Extrinsic;
import com.limechain.transaction.dto.ValidTransaction;
import com.limechain.utils.StringUtils;
import io.emeraldpay.polkaj.schnorrkel.Schnorrkel;
import io.emeraldpay.polkaj.schnorrkel.SchnorrkelException;
import io.libp2p.crypto.keys.Ed25519PrivateKey;
import org.apache.tomcat.util.buf.HexUtils;
import org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters;
import org.javatuples.Pair;
import org.springframework.stereotype.Service;
Expand All @@ -22,9 +28,14 @@
public class AuthorRPCImpl {

private final BlockState blockState;
//TODO: Check if these dependencies can be injected with AppBean?
private final TransactionState transactionState;
private final TransactionValidator transactionValidator;
private final KeyStore keyStore;

public AuthorRPCImpl(KeyStore keyStore) {
public AuthorRPCImpl(TransactionState transactionState, TransactionValidator transactionValidator, KeyStore keyStore) {
this.transactionState = transactionState;
this.transactionValidator = transactionValidator;
this.blockState = BlockState.getInstance();
this.keyStore = keyStore;
}
Expand Down Expand Up @@ -82,8 +93,20 @@ public Boolean authorHasSessionKeys(String sessionKeys) {
return true;
}

public String authorSubmitExtrinsic(String extrinsics) {
return "";
public String authorSubmitExtrinsic(String extrinsic) {
//TODO: only for authoring node -> validate if transactionState is not null
Extrinsic parsedExtrinsic = new Extrinsic(StringUtils.hexToBytes(extrinsic));

ValidTransaction validTransaction;
try {
validTransaction = transactionValidator.validateExternalTransaction(parsedExtrinsic);
} catch (TransactionValidationException e) {
throw new ExecutionFailedException("Failed to executed submit_extrinsic call: " + e.getMessage());
}

return HexUtils.toHexString(
transactionState.addToPool(validTransaction)
);
}

public String authorSubmitAndWatchExtrinsic(String extrinsics) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/limechain/trie/cache/TrieChanges.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public static TrieChanges empty() {
*/
public static TrieChanges copy(TrieChanges original) {
TreeMap<Nibbles, PendingTrieNodeChange> copyChanges = new TreeMap<>();
// TODO: Dirty fix for ConcurrentModificationException
// var temp = (TreeMap<Nibbles, PendingTrieNodeChange>) original.changes.clone();
// temp.forEach((key, value) -> {
original.changes.forEach((key, value) -> {
PendingTrieNodeChange trieNodeChange = value instanceof PendingInsertUpdate u
? new PendingInsertUpdate(u)
Expand Down

0 comments on commit 7b7bf5d

Please sign in to comment.