Skip to content

Commit

Permalink
Add description/README
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjort committed Jan 4, 2023
1 parent 7b242cd commit f462041
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions packages/common/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,26 @@ const updateContractTransaction: AccountTransaction = {
```
Finally, to actually update the contract on the chain, send the constructed `updateContractTransaction` to the chain using `sendAccountTransaction`. (See [Send Account Transaction](#Send-Account-Transaction) for how to do this)

## Serialize parameters with only the specific type's schema
In the previous section the schema used was assumed to be the schema for an entire module. In some cases one might want to use a schema containing only the specific type of the parameter.

For this, the function `serializeTypeValue` can used.
```
const inputParams = serializeTypeValue(userInput, rawTypeSchema);
```

For reference, the type schema for parameters can be extracted using the functions `getInitContractParameterSchema` and `getUpdateContractParameterSchema`.

```
const rawTypeSchema = getUpdateContractParameterSchema(
rawModuleSchema,
contractName,
receiveFunctionName,
userInput,
schemaVersion
)
```

# Utility functions

## Generate account alias
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/serialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ export function serializeUpdateContractParameters(
}

/**
* @param value the value that should be serialized. Should correspond to the JSON representation.
* Given a value for a smart contract type, and the raw schema for that type, serialize the value into binary format.
* @param value the value that should be serialized. Should correspond to the JSON representation
* @param rawSchema the schema for the type that the given value should be serialized as
* @returns serialized buffer of the value
*/
Expand Down

0 comments on commit f462041

Please sign in to comment.