-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: checking if the requested blueprint exists in the fullnode #16
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import { HathorWallet } from '@hathor/wallet-lib'; | ||
import { HathorWallet, ncApi } from '@hathor/wallet-lib'; | ||
import { | ||
TriggerTypes, | ||
PinConfirmationPrompt, | ||
|
@@ -19,7 +19,13 @@ import { | |
RpcResponseTypes, | ||
RpcResponse, | ||
} from '../types'; | ||
import { PromptRejectedError, SendNanoContractTxError } from '../errors'; | ||
import { | ||
BluePrintNotFoundError, | ||
ParamsValidationError, | ||
PromptRejectedError, | ||
SendNanoContractTxError, | ||
} from '../errors'; | ||
import { NanoRequest404Error } from '@hathor/wallet-lib/lib/errors'; | ||
|
||
/** | ||
* Sends a nano contract transaction. | ||
|
@@ -55,6 +61,20 @@ export async function sendNanoContractTx( | |
throw new Error('Neither blueprint id or ncId available'); | ||
} | ||
|
||
// Validate that the blueprintId exists | ||
if (blueprint_id) { | ||
try { | ||
// Just fetch it to check if it's a valid blueprint | ||
await ncApi.getBlueprintInformation(blueprint_id); | ||
} catch (error) { | ||
if (error instanceof NanoRequest404Error) { | ||
throw new BluePrintNotFoundError(); | ||
} | ||
|
||
throw new ParamsValidationError(); | ||
} | ||
} | ||
|
||
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. We should also check that the 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. todo: I believe it is lacking a validation on the methods existence after confirming that the blueprint exists. |
||
const pinPrompt: PinConfirmationPrompt = { | ||
type: TriggerTypes.PinConfirmationPrompt, | ||
method: rpcRequest.method, | ||
|
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.