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

ICS30: Update callbacks #790

Merged
merged 1 commit into from
Jul 11, 2022
Merged
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
36 changes: 28 additions & 8 deletions spec/app/ics-030-middleware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,17 @@ function onChanOpenInit(
channelIdentifier: Identifier,
counterpartyPortIdentifier: Identifier,
counterpartyChannelIdentifier: Identifier,
version: string) {
middlewareVersion, appVersion = splitMiddlewareVersion(version)
version: string) (version: string, err: Error) {
if version != "" {
middlewareVersion, appVersion = splitMiddlewareVersion(version)
} else {
// set middleware version to default value
middlewareVersion = defaultMiddlewareVersion
// allow application to return its default version
appVersion = ""
}
doCustomLogic()
app.OnChanOpenInit(
appVersion, err = app.OnChanOpenInit(
order,
connectionHops,
portIdentifier,
Expand All @@ -101,6 +108,12 @@ function onChanOpenInit(
counterpartyChannelIdentifier,
appVersion, // note we only pass app version here
)
abortTransactionUnless(err != nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we call abortTransactionUnless here, is there a reason to return Error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true, but I'm just trying to stay consistent with the ICS26 function signature. In practice, the abortTransaction process is carried out by returning an error at this level.

versionJSON = {
middlewareVersion: middlewareVersion, // note this should have a different field name specific to middleware
appVersion: appVersion
}
return marshalJSON(versionJSON), nil
}

function OnChanOpenTry(
Expand All @@ -110,17 +123,18 @@ function OnChanOpenTry(
channelIdentifier: Identifier,
counterpartyPortIdentifier: Identifier,
counterpartyChannelIdentifier: Identifier,
version: string,
counterpartyVersion: string) {
counterpartyVersion: string) (version: string, err: Error) {
cpMiddlewareVersion, cpAppVersion = splitMiddlewareVersion(counterpartyVersion)
middlewareVersion, appVersion = splitMiddlewareVersion(version)
if !isCompatible(cpMiddlewareVersion, middlewareVersion) {
if !isSupported(cpMiddlewareVersion) {
return error
}
// create our middleware version based on the version passed in by counterparty
middlewareVersion = constructVersion(cpMiddlewareVersion)

doCustomLogic()

// call the underlying applications OnChanOpenTry callback
app.OnChanOpenTry(
appVersion, err = app.OnChanOpenTry(
order,
connectionHops,
portIdentifier,
Expand All @@ -130,6 +144,12 @@ function OnChanOpenTry(
cpAppVersion, // note we only pass counterparty app version here
appVersion, // only pass app version
)
abortTransactionUnless(err != nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

versionJSON = {
middlewareVersion: middlewareVersion, // note this should have a different field name specific to middleware
appVersion: appVersion
}
return marshalJSON(versionJSON), nil
}

function onChanOpenAck(
Expand Down