Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transaction simulation failed: Error processing Instruction 1: custom program error: 0xc #32

Open
Juangunner4 opened this issue Aug 14, 2024 · 0 comments

Comments

@Juangunner4
Copy link

Juangunner4 commented Aug 14, 2024

I am getting this error below when creating tokens

java.lang.RuntimeException: Failed to create brand tokens\r\n\tat com.scripledger.services.SolanaService.lambda$createBrandToken$4(SolanaService.java:191)\r\n\tat io.smallrye.context.impl.wrappers.SlowContextualSupplier.get(SlowContextualSupplier.java:21)\r\n\tat io.smallrye.mutiny.operators.uni.builders.UniCreateFromItemSupplier.subscribe(UniCreateFromItemSupplier.java:28)\r\n\tat io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni.subscribe(UniOnItemTransformToUni.java:25)\r\n\tat io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni$UniOnItemTransformToUniProcessor.performInnerSubscription(UniOnItemTransformToUni.java:81)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransformToUni$UniOnItemTransformToUniProcessor.onItem(UniOnItemTransformToUni.java:57)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransform$UniOnItemTransformProcessor.onItem(UniOnItemTransform.java:43)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransform$UniOnItemTransformProcessor.onItem(UniOnItemTransform.java:43)\r\n\tat io.smallrye.mutiny.operators.uni.UniOnItemTransform$UniOnItemTransformProcessor.onItem(UniOnItemTransform.java:43)\r\n\tat io.smallrye.mutiny.operators.uni.builders.UniCreateFromPublisher$PublisherSubscriber.onComplete(UniCreateFromPublisher.java:86)\r\n\tat io.smallrye.mutiny.subscription.MultiSubscriberAdapter.onCompletion(MultiSubscriberAdapter.java:37)\r\n\tat io.smallrye.mutiny.operators.multi.MultiEmitOnOp$MultiEmitOnProcessor.isDoneOrCancelled(MultiEmitOnOp.java:248)\r\n\tat io.smallrye.mutiny.operators.multi.MultiEmitOnOp$MultiEmitOnProcessor.run(MultiEmitOnOp.java:188)\r\n\tat io.quarkus.mongodb.impl.Wrappers.lambda$toMulti$2(Wrappers.java:32)\r\n\tat io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:279)\r\n\tat io.vertx.core.impl.ContextInternal.dispatch(ContextInternal.java:261)\r\n\tat io.vertx.core.impl.ContextInternal.lambda$runOnContext$0(ContextInternal.java:59)\r\n\tat io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:173)\r\n\tat io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:166)\r\n\tat io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)\r\n\tat io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:569)\r\n\tat io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)\r\n\tat io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)\r\n\tat io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)\r\n\tat java.base/java.lang.Thread.run(Thread.java:842)\r\nCaused by: java.lang.RuntimeException: Transaction failed\r\n\tat com.scripledger.services.SolanaService.lambda$sendTransaction$7(SolanaService.java:215)\r\n\tat io.smallrye.context.impl.wrappers.SlowContextualConsumer.accept(SlowContextualConsumer.java:21)\r\n\tat io.smallrye.mutiny.helpers.UniCallbackSubscriber.onFailure(UniCallbackSubscriber.java:62)\r\n\tat io.smallrye.mutiny.operators.uni.builders.UniCreateFromItemSupplier.subscribe(UniCreateFromItemSupplier.java:31)\r\n\tat io.smallrye.mutiny.operators.AbstractUni.subscribe(AbstractUni.java:36)\r\n\tat io.smallrye.mutiny.groups.UniSubscribe.withSubscriber(UniSubscribe.java:51)\r\n\tat io.smallrye.mutiny.groups.UniSubscribe.with(UniSubscribe.java:110)\r\n\tat io.smallrye.mutiny.groups.UniSubscribe.with(UniSubscribe.java:88)\r\n\tat com.scripledger.services.SolanaService.sendTransaction(SolanaService.java:211)\r\n\tat com.scripledger.services.SolanaService.lambda$createBrandToken$4(SolanaService.java:181)\r\n\t... 26 more\r\nCaused by: java.lang.RuntimeException: Failed to send transaction\r\n\tat com.scripledger.services.SolanaService.lambda$sendTransaction$5(SolanaService.java:206)\r\n\tat io.smallrye.context.impl.wrappers.SlowContextualSupplier.get(SlowContextualSupplier.java:21)\r\n\tat io.smallrye.mutiny.operators.uni.builders.UniCreateFromItemSupplier.subscribe(UniCreateFromItemSupplier.java:28)\r\n\t... 32 more\r\nCaused by: org.p2p.solanaj.rpc.RpcException: Transaction simulation failed: Error processing Instruction 1: custom program error: 0xc\r\n\tat org.p2p.solanaj.rpc.RpcClient.call(RpcClient.java:51)\r\n\tat org.p2p.solanaj.rpc.RpcApi.sendTransaction(RpcApi.java:51)\r\n\tat com.scripledger.services.SolanaService.lambda$sendTransaction$5(SolanaService.java:201)\r\n\t... 34 more"

public Uni<Uni<String>> createBrandToken(String ownerPublicKeyStr, Long initialSupply) {
    return Uni.createFrom().item(() -> {
        try {
            PublicKey ownerPublicKey = new PublicKey(ownerPublicKeyStr);

            // Log owner account public key
            LOGGER.info("Owner account public key: " + ownerPublicKey);

            Account mintAccount = new Account();
            PublicKey mintPublicKey = mintAccount.getPublicKey();

            // Log mint account public key
            LOGGER.info("Mint account public key: " + mintPublicKey.toString());
            Transaction transaction = new Transaction();

            long lamportsForRentExemption = getMinimumBalanceForRentExemption();

            TransactionInstruction createAccountInstruction = SystemProgram.createAccount(
                    ownerPublicKey,
                    mintPublicKey,
                    lamportsForRentExemption,
                    TokenProgram.MINT_LAYOUT_SIZE,
                    TokenProgram.PROGRAM_ID
            );

            byte[] data = ByteBuffer.allocate(9)
                    .order(ByteOrder.LITTLE_ENDIAN)
                    .put((byte) 0) // InitializeMint instruction index for the Token Program
                    .putLong(initialSupply)
                    .array();

            AccountMeta mintAccountMeta = new AccountMeta(mintPublicKey, false, true);
            AccountMeta ownerAccountMeta = new AccountMeta(ownerPublicKey, true, false);

            TransactionInstruction mintInstruction = new TransactionInstruction(
                    TokenProgram.PROGRAM_ID,
                    Arrays.asList(mintAccountMeta, ownerAccountMeta),
                    data
            );

            transaction.addInstruction(createAccountInstruction);
            transaction.addInstruction(mintInstruction);

            // Log details of the transaction instructions
            LOGGER.info("Transaction instructions added:");
            logTransactionInstruction(createAccountInstruction);
            logTransactionInstruction(mintInstruction);

            return sendTransaction(transaction, mintAccount)
                    .onItem().transform(signature -> {
                        LOGGER.info("Transaction successful with signature: " + signature);
                        return signature;
                    })
                    .onFailure().invoke(e -> {
                        LOGGER.error("Transaction failed", e);
                    });
        } catch (Exception e) {
            LOGGER.error("Failed to create brand tokens", e);
            throw new RuntimeException("Failed to create brand tokens", e);
        }
    });
}

public Uni<String> sendTransaction(Transaction transaction, Account signer) throws IOException {
    Account feePayerAccount = new Account(Base58.decode(retrievePrivateKey())); // Load fee payer account
    List<Account> signers = Arrays.asList(feePayerAccount, signer);
    Uni<String> uni = Uni.createFrom().item(() -> {
        try {
            String signature = client.getApi().sendTransaction(transaction, signers);
            LOGGER.info("Transaction sent with signature: " + signature);
            return signature;
        } catch (RpcException e) {
            LOGGER.error("Failed to send transaction", e);
            throw new RuntimeException("Failed to send transaction", e);
        }
    });

    // Force subscription and handle errors
    uni.subscribe().with(
            signature -> LOGGER.info("Transaction successful with signature: " + signature),
            failure -> {
                LOGGER.error("Transaction failed", failure);
                throw new RuntimeException("Transaction failed", failure);
            }
    );

    return uni;
}

private void logTransactionInstruction(TransactionInstruction instruction) {
   
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant