-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from Concordium/serialize-type-value
Add function to serialize parameters with the direct type schemas
- Loading branch information
Showing
15 changed files
with
259 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Buffer } from 'buffer/'; | ||
import { SchemaVersion } from './types'; | ||
import * as wasm from '@concordium/rust-bindings'; | ||
|
||
/** | ||
* @param moduleSchema buffer for the schema of a module that contains the contract | ||
* @param contractName name of the contract that the init contract transaction will initialize | ||
* @param schemaVersion the version of the schema provided | ||
* @returns buffer containing the schema for of init contract parameters | ||
*/ | ||
export function getInitContractParameterSchema( | ||
moduleSchema: Buffer, | ||
contractName: string, | ||
schemaVersion?: SchemaVersion | ||
): Buffer { | ||
const parameterSchema = wasm.getInitContractParameterSchema( | ||
moduleSchema.toString('hex'), | ||
contractName, | ||
schemaVersion | ||
); | ||
try { | ||
return Buffer.from(parameterSchema, 'hex'); | ||
} catch (e) { | ||
throw new Error( | ||
'unable to get parameter schema, due to: ' + parameterSchema | ||
); // In this case parameterSchema is the error message from the rust module | ||
} | ||
} | ||
|
||
/** | ||
* @param moduleSchema buffer for the schema of a module that contains the contract | ||
* @param contractName name of the contract that the update contract transaction will update | ||
* @param receiveFunctionName name of function that the update contract transaction will invoke | ||
* @param schemaVersion the version of the schema provided | ||
* @returns buffer containing the schema for of update contract parameters | ||
*/ | ||
export function getUpdateContractParameterSchema( | ||
moduleSchema: Buffer, | ||
contractName: string, | ||
receiveFunctionName: string, | ||
schemaVersion?: SchemaVersion | ||
): Buffer { | ||
const parameterSchema = wasm.getReceiveContractParameterSchema( | ||
moduleSchema.toString('hex'), | ||
contractName, | ||
receiveFunctionName, | ||
schemaVersion | ||
); | ||
try { | ||
return Buffer.from(parameterSchema, 'hex'); | ||
} catch (e) { | ||
throw new Error( | ||
'unable to get parameter schema, due to: ' + parameterSchema | ||
); // In this case parameterSchema is the error message from the rust module | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.