Skip to content

Unite p2sAddress and p2shAddress routes (#2213) - #2454

Open
beejaygee wants to merge 1 commit into
ergoplatform:masterfrom
beejaygee:codex/issue-2213
Open

Unite p2sAddress and p2shAddress routes (#2213)#2454
beejaygee wants to merge 1 commit into
ergoplatform:masterfrom
beejaygee:codex/issue-2213

Conversation

@beejaygee

Copy link
Copy Markdown

Closes #2213

Summary

ScriptApiRoute.p2sAddressR and p2shAddressR were nearly identical, differing only in whether the compiled ErgoTree was wrapped with Pay2SAddress.apply or Pay2SHAddress.apply, per the repo's own // todo: unite p2sAddress and p2shAddress comment referencing this issue.

Extracted the shared logic into compiledAddressR(wrapAddress: ErgoTree => ErgoAddress), and both routes now delegate to it:

private def p2sAddressR: Route = path("p2sAddress") { compiledAddressR(Pay2SAddress.apply) }
private def p2shAddressR: Route = path("p2shAddress") { compiledAddressR(Pay2SHAddress.apply) }

No behavior change: same request handling, validation, and response shape for both routes.

Testing

sbt "testOnly org.ergoplatform.http.routes.ScriptApiRouteSpec" — 10/10 passed, run in an isolated Docker sandbox against upstream master (4a7dba0), including the two directly relevant cases:

[info] ScriptApiRouteSpec:
[info] - should execute script with context
[info] - should generate valid P2SAddress form source
[info] - should generate valid P2SHAddress form source
[info] - should get through address <-> ergoTree round-trip
[info] - should address <-> bytes roundtrip via addressToBytes
[info] - should generate addresses with different tree versions
[info] - should handle tree version 2 for P2SH address
[info] - should generate consistent addresses for same script and version
[info] - should generate different addresses for different tree versions
[info] - should handle P2SH with tree version 1 (should still use version 0)
[info] Tests: succeeded 10, failed 0, canceled 0, ignored 0, pending 0

Note on prior attempt

An earlier PR for this issue (#2250) received a maintainer approval (@kushti) but was closed unmerged without comment, and no PR has been open against it since. Reserved via ErgoDevs/Ergo-Bounties before opening this.

Extracts the shared implementation of p2sAddressR and p2shAddressR into
a single compiledAddressR(wrapAddress) helper, parameterized by
Pay2SAddress.apply / Pay2SHAddress.apply -- the only point where the
two routes previously differed.

Behavior-preserving: all 10 existing tests in ScriptApiRouteSpec pass
unchanged.
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

Successfully merging this pull request may close these issues.

Unite script/p2sAddress & script/p2shAddress

1 participant