Skip to content

Commit

Permalink
first pass to deprecate signTransactions (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
Funkatronics authored Oct 20, 2023
1 parent e935f7a commit b24dec1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class LocalAdapterOperations(
}
}

@Deprecated("signTransactions is deprecated in MWA 2.0, use signAndSendTransactions",
replaceWith = ReplaceWith("signAndSendTransactions(transactions, DefaultTransactionParams)"),
DeprecationLevel.WARNING)
override suspend fun signTransactions(transactions: Array<ByteArray>): MobileWalletAdapterClient.SignPayloadsResult {
return withContext(ioDispatcher) {
@Suppress("BlockingMethodInNonBlockingContext")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ sealed class Solana {
}

open class TransactionParams(
val minContextSlot: Int?
val minContextSlot: Int?,
val commitment: String?,
val skipPreflight: Boolean?,
val maxRetries: Int?,
val waitForCommitmentToSendNextTransaction: Boolean?
)

//TODO: We can add other defaults as they become relevant
object DefaultTransactionParams : TransactionParams(
minContextSlot = null
minContextSlot = null,
commitment = null,
skipPreflight = null,
maxRetries = null,
waitForCommitmentToSendNextTransaction = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ public String getMessage() {
// sign_transactions
// =============================================================================================

@Deprecated(since = "2.0.0", forRemoval = true)
@NonNull
public SignPayloadsFuture signTransactions(@NonNull @Size(min = 1) byte[][] transactions)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class ProtocolContract {
@Deprecated
public static final String RESULT_SUPPORTS_SIGN_AND_SEND_TRANSACTIONS = "supports_sign_and_send_transactions"; // type: Boolean

@Deprecated(since = "2.0.0", forRemoval = true)
public static final String METHOD_SIGN_TRANSACTIONS = "sign_transactions";
// METHOD_SIGN_TRANSACTIONS takes a PARAMETER_PAYLOADS
// METHOD_SIGN_TRANSACTIONS returns a RESULT_SIGNED_PAYLOADS
Expand All @@ -47,6 +48,10 @@ public class ProtocolContract {
// METHOD_SIGN_AND_SEND_TRANSACTIONS takes a PARAMETER_PAYLOADS
public static final String PARAMETER_OPTIONS = "options"; // type: JSON object
public static final String PARAMETER_OPTIONS_MIN_CONTEXT_SLOT = "min_context_slot"; // type: Number
public static final String PARAMETER_OPTIONS_COMMITMENT = "commitment"; // type: String
public static final String PARAMETER_OPTIONS_SKIP_PREFLIGHT = "skip_preflight"; // type: String
public static final String PARAMETER_OPTIONS_MAX_RETRIES = "max_retries"; // type: Number
public static final String PARAMETER_OPTIONS_WAIT_FOR_COMMITMENT = "wait_for_commitment_to_send_next_transaction"; // type: Boolean
public static final String RESULT_SIGNATURES = "signatures"; // type: JSON array of String (base64-encoded payload signatures)

public static final String METHOD_SIGN_MESSAGES = "sign_messages";
Expand Down Expand Up @@ -106,13 +111,13 @@ public class ProtocolContract {
public static final String NAMESPACE_SOLANA = "solana";

// Mandatory Features
public static final String FEATURE_ID_SIGN_MESSAGES = "solana:signAndSendTransaction";
public static final String FEATURE_ID_SIGN_TRANSACTIONS = "solana:signTransactions";
public static final String FEATURE_ID_SIGN_MESSAGES = "solana:signMessages";
public static final String FEATURE_ID_SIGN_AND_SEND_TRANSACTIONS = "solana:signAndSendTransaction";

// Optional Features
public static final String FEATURE_ID_SIGN_AND_SEND_TRANSACTIONS = "solana:signAndSendTransaction";
public static final String FEATURE_ID_SIGN_IN_WITH_SOLANA = "solana:signInWithSolana";
public static final String FEATURE_ID_CLONE_AUTHORIZATION = "solana:cloneAuthorization";
public static final String FEATURE_ID_SIGN_TRANSACTIONS = "solana:signTransactions";

private ProtocolContract() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ public class MobileWalletAdapterConfig {
@NonNull
public final String[] optionalFeatures;

@Deprecated
@Deprecated(since = "2.0.0", forRemoval = true)
public MobileWalletAdapterConfig(boolean supportsSignAndSendTransactions,
@IntRange(from = 0) int maxTransactionsPerSigningRequest,
@IntRange(from = 0) int maxMessagesPerSigningRequest,
@NonNull @Size(min = 1) Object[] supportedTransactionVersions,
@IntRange(from = 0) long noConnectionWarningTimeoutMs) {
this(maxTransactionsPerSigningRequest, maxMessagesPerSigningRequest,
supportedTransactionVersions, noConnectionWarningTimeoutMs,
supportsSignAndSendTransactions ? new String[] {
ProtocolContract.FEATURE_ID_SIGN_AND_SEND_TRANSACTIONS } : new String[] {},
new String[] { ProtocolContract.FEATURE_ID_SIGN_TRANSACTIONS },
List.of(SessionProperties.ProtocolVersion.LEGACY));
if (!supportsSignAndSendTransactions)
throw new IllegalArgumentException("signAndSendTransactions is required in MWA 2.0");
}

public MobileWalletAdapterConfig(@IntRange(from = 0) int maxTransactionsPerSigningRequest,
Expand All @@ -65,6 +66,7 @@ public MobileWalletAdapterConfig(@IntRange(from = 0) int maxTransactionsPerSigni
this.noConnectionWarningTimeoutMs = noConnectionWarningTimeoutMs;
this.supportedProtocolVersions = supportedProtocolVersions;
this.optionalFeatures = supportedFeatures;
this.supportsSignAndSendTransactions = true;

for (Object o : supportedTransactionVersions) {
if (!((o instanceof String) && LEGACY_TRANSACTION_VERSION.equals((String)o)) &&
Expand All @@ -74,16 +76,10 @@ public MobileWalletAdapterConfig(@IntRange(from = 0) int maxTransactionsPerSigni
}
this.supportedTransactionVersions = supportedTransactionVersions;

boolean supportsSignAndSendTransactions = false;
for (String featureId : supportedFeatures) {
if (!Identifier.isValidIdentifier(featureId)) {
throw new IllegalArgumentException("supportedFeatures must be a valid namespaced feature identifier of the form '{namespace}:{reference}'");
}
if (featureId.equals(ProtocolContract.FEATURE_ID_SIGN_AND_SEND_TRANSACTIONS)) {
supportsSignAndSendTransactions = true;
break;
}
}
this.supportsSignAndSendTransactions = supportsSignAndSendTransactions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ protected void dispatchRpc(@Nullable Object id,
handleGetCapabilities(id, params);
break;
case ProtocolContract.METHOD_SIGN_TRANSACTIONS:
handleSignTransactions(id, params);
if (Arrays.asList(mConfig.optionalFeatures).contains(ProtocolContract.FEATURE_ID_SIGN_TRANSACTIONS)) {
handleSignTransactions(id, params);
} else {
handleRpcError(id, JsonRpc20Server.ERROR_METHOD_NOT_FOUND, "method '" +
ProtocolContract.METHOD_SIGN_TRANSACTIONS +
"' not available", null);
}
break;
case ProtocolContract.METHOD_SIGN_MESSAGES:
handleSignMessages(id, params);
break;
case ProtocolContract.METHOD_SIGN_AND_SEND_TRANSACTIONS:
if (mConfig.supportsSignAndSendTransactions) {
handleSignAndSendTransactions(id, params);
} else {
handleRpcError(id, JsonRpc20Server.ERROR_METHOD_NOT_FOUND, "method '" +
ProtocolContract.METHOD_SIGN_AND_SEND_TRANSACTIONS +
"' not available", null);
}
handleSignAndSendTransactions(id, params);
break;
default:
handleRpcError(id, JsonRpc20Server.ERROR_METHOD_NOT_FOUND, "method '" +
Expand Down Expand Up @@ -718,6 +718,7 @@ public enum SigningType { Transaction, Message }
// sign_transactions
// =============================================================================================

@Deprecated(since = "2.0.0", forRemoval = true)
private void handleSignTransactions(@Nullable Object id,
@Nullable Object params)
throws IOException {
Expand Down

0 comments on commit b24dec1

Please sign in to comment.