Skip to content

Commit

Permalink
Convenience methods to re-create transactions from skeletons.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpe7s committed Jan 21, 2025
1 parent 830df99 commit 1efff00
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
24 changes: 19 additions & 5 deletions core/src/main/java/software/sava/core/tx/TransactionSkeleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import software.sava.core.programs.Discriminator;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -227,26 +228,39 @@ default Instruction[] filterInstructionsWithoutTableAccounts(final Discriminator

Instruction[] filterInstructionsWithoutAccounts(final Discriminator discriminator);

Transaction createTransaction(final AccountMeta[] accounts);
Transaction createTransaction(final List<Instruction> instructions);

default Transaction createTransaction(AccountMeta[] accounts) {
final var instructions = parseInstructions(accounts);
return createTransaction(Arrays.asList(instructions));
}

default Transaction createTransaction() {
final var accounts = parseAccounts();
return createTransaction(accounts);
}

Transaction createTransaction(final AccountMeta[] accounts,
final AddressLookupTable lookupTable);
Transaction createTransaction(final List<Instruction> instructions, final AddressLookupTable lookupTable);

default Transaction createTransaction(final AccountMeta[] accounts, final AddressLookupTable lookupTable) {
final var instructions = parseInstructions(accounts);
return createTransaction(Arrays.asList(instructions), lookupTable);
}

default Transaction createTransaction(final AddressLookupTable lookupTable) {
final var accounts = parseAccounts(lookupTable);
return createTransaction(accounts, lookupTable);
}

Transaction createTransaction(final AccountMeta[] accounts,
final LookupTableAccountMeta[] tableAccountMetas);
default Transaction createTransaction(final AccountMeta[] accounts, final LookupTableAccountMeta[] tableAccountMetas) {
final var instructions = parseInstructions(accounts);
return createTransaction(Arrays.asList(instructions), tableAccountMetas);
}

default Transaction createTransaction(final LookupTableAccountMeta[] tableAccountMetas) {
final var accounts = parseAccounts(Arrays.stream(tableAccountMetas).map(LookupTableAccountMeta::lookupTable));
return createTransaction(accounts, tableAccountMetas);
}

Transaction createTransaction(final List<Instruction> instructions, final LookupTableAccountMeta[] tableAccountMetas);
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,10 @@ public Instruction[] parseInstructionsWithoutTableAccounts() {
}

@Override
public Transaction createTransaction(final AccountMeta[] accounts) {
public Transaction createTransaction(final List<Instruction> instructions) {
return new TransactionRecord(
AccountMeta.createFeePayer(feePayer()),
Arrays.asList(parseInstructions(accounts)),
instructions,
null,
TransactionRecord.NO_TABLES,
data,
Expand All @@ -348,11 +348,11 @@ public Transaction createTransaction(final AccountMeta[] accounts) {
}

@Override
public Transaction createTransaction(final AccountMeta[] accounts,
public Transaction createTransaction(final List<Instruction> instructions,
final AddressLookupTable lookupTable) {
return new TransactionRecord(
AccountMeta.createFeePayer(feePayer()),
Arrays.asList(parseInstructions(accounts)),
instructions,
lookupTable,
TransactionRecord.NO_TABLES,
data,
Expand All @@ -363,11 +363,11 @@ public Transaction createTransaction(final AccountMeta[] accounts,
}

@Override
public Transaction createTransaction(final AccountMeta[] accounts,
public Transaction createTransaction(final List<Instruction> instructions,
final LookupTableAccountMeta[] tableAccountMetas) {
return new TransactionRecord(
AccountMeta.createFeePayer(feePayer()),
Arrays.asList(parseInstructions(accounts)),
instructions,
null,
tableAccountMetas,
data,
Expand Down

0 comments on commit 1efff00

Please sign in to comment.