Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions packages/core-ts/src/routing/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,25 @@ export function extractRouting(input: RoutingInput): RoutingResult {
}

if (parsed.kind === "C") {

const warnings: Warning[] = [...parsed.warnings];

warnings.push({
code: "CONTRACT_SENDER_DETECTED",
severity: "warn",
message:
"Contract address detected. Contract addresses cannot be used as transaction senders.",
});

return {
destinationBaseAccount: null,
routingId: null,
routingSource: "none",
warnings,
};

throw new ExtractRoutingError("Contract addresses cannot be routed");

}

if (parsed.kind === "M") {
Expand Down Expand Up @@ -118,17 +136,15 @@ export function extractRouting(input: RoutingInput): RoutingResult {
}
} else if (input.memoType === "hash" || input.memoType === "return") {
warnings.push({
code: "UNSUPPORTED_MEMO_TYPE",
code: "MEMO_TEXT_UNROUTABLE",
severity: "warn",
message: `Memo type ${input.memoType} is not supported for routing.`,
context: { memoType: input.memoType },
});
} else if (input.memoType !== "none") {
warnings.push({
code: "UNSUPPORTED_MEMO_TYPE",
code: "MEMO_TEXT_UNROUTABLE",
severity: "warn",
message: `Unrecognized memo type: ${input.memoType}`,
context: { memoType: "unknown" },
});
}

Expand Down
10 changes: 4 additions & 6 deletions packages/core-ts/src/routing/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ErrorCode, Warning } from "../address/types";

export type RoutingSource = "muxed" | "memo" | "none";

export type RoutingInput = {
destination: string;
memoType: string;
Expand All @@ -12,18 +14,14 @@ export type KnownMemoType = "none" | "id" | "text" | "hash" | "return";
export type RoutingResult = {
destinationBaseAccount: string | null;
routingId: string | null; // decimal uint64 string — spec level
routingSource: "muxed" | "memo" | "none";
routingSource: RoutingSource;
warnings: Warning[]; // WarningCode only, always
destinationError?: {
// ErrorCode only, when destination unparseable
code: ErrorCode;
message: string;
};
};

/**
* Ergonomic helper for TypeScript callers to get a BigInt from the routingId string.
*/
export function routingIdAsBigInt(routingId: string | null): bigint | null {
return routingId ? BigInt(routingId) : null;
}
}
Loading