-
Notifications
You must be signed in to change notification settings - Fork 34
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
Added MintInfo Class #209
base: development
Are you sure you want to change the base?
Added MintInfo Class #209
Changes from 6 commits
d1c0acf
911b05c
bbd3844
cbfd9d2
8eb42d2
e8e00b9
5a36b42
b47fd61
f5d8b51
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { GetInfoResponse, MPPMethod, SwapMethod, WebSocketSupport } from './types'; | ||
|
||
export class MintInfo { | ||
private readonly mintInfo: GetInfoResponse; | ||
|
||
constructor(info: GetInfoResponse) { | ||
this.mintInfo = info; | ||
} | ||
|
||
isSupported(num: 4 | 5): { disabled: boolean; params: Array<SwapMethod> }; | ||
isSupported(num: 7 | 8 | 9 | 10 | 11 | 12 | 14): { supported: boolean }; | ||
isSupported(num: 17): { supported: boolean; params?: Array<WebSocketSupport> }; | ||
isSupported(num: 15): { supported: boolean; params?: Array<MPPMethod> }; | ||
isSupported(num: number) { | ||
switch (num) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the cases be handled exhaustively so that unrecognized NUT numbers always resolve to false? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very good point! I added a default case that throws. Throwing in this case makes more sense to me, because it makes clear that this NUT is unsupported by the client, not the mint |
||
case 4: | ||
case 5: { | ||
return this.checkMintMelt(num); | ||
} | ||
case 7: | ||
case 8: | ||
case 9: | ||
case 10: | ||
case 11: | ||
case 12: | ||
case 14: { | ||
return this.checkGenericNut(num); | ||
} | ||
case 17: { | ||
return this.checkNut17(); | ||
} | ||
case 15: { | ||
return this.checkNut15(); | ||
} | ||
} | ||
} | ||
private checkGenericNut(num: 7 | 8 | 9 | 10 | 11 | 12 | 14) { | ||
if (this.mintInfo.nuts[num]?.supported) { | ||
return { supported: true }; | ||
} | ||
return { supported: false }; | ||
} | ||
private checkMintMelt(num: 4 | 5) { | ||
const mintMeltInfo = this.mintInfo.nuts[num]; | ||
if (mintMeltInfo && mintMeltInfo.methods.length > 0 && !mintMeltInfo.disabled) { | ||
return { disabled: false, params: mintMeltInfo.methods }; | ||
} | ||
return { disabled: true, params: mintMeltInfo.methods }; | ||
} | ||
private checkNut17() { | ||
if (this.mintInfo.nuts['17'] && this.mintInfo.nuts[17].supported.length > 0) { | ||
Egge21M marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return { supported: true, params: this.mintInfo.nuts[17].supported }; | ||
} | ||
return { supported: false }; | ||
} | ||
private checkNut15() { | ||
if (this.mintInfo.nuts['15'] && this.mintInfo.nuts[15].methods.length > 0) { | ||
return { supported: true, params: this.mintInfo.nuts[15].methods }; | ||
} | ||
return { supported: false }; | ||
} | ||
|
||
get contact() { | ||
return this.mintInfo.contact; | ||
} | ||
|
||
get description() { | ||
return this.mintInfo.description; | ||
} | ||
|
||
get description_long() { | ||
return this.mintInfo.description_long; | ||
} | ||
|
||
get name() { | ||
return this.mintInfo.name; | ||
} | ||
|
||
get pubkey() { | ||
return this.mintInfo.pubkey; | ||
} | ||
|
||
get version() { | ||
return this.mintInfo.version; | ||
} | ||
|
||
get motd() { | ||
return this.mintInfo.motd; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we use
_mintInfo
to match other private fields?