-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
137 additions
and
16 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
1 change: 1 addition & 0 deletions
1
packages/massa-web3/src/experimental/generated/deployer-bytecode.ts
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
18 changes: 18 additions & 0 deletions
18
packages/massa-web3/src/experimental/generated/generate-deployer.js
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,18 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const wasmPath = path.join(__dirname,'deployer.wasm'); | ||
|
||
const wasmData = fs.readFileSync(wasmPath); | ||
|
||
const base64WasmData = wasmData.toString('base64'); | ||
|
||
const byteArray = Uint8Array.from(Buffer.from(base64WasmData, 'base64')); | ||
|
||
const byteString = Array.from(byteArray).join(','); | ||
|
||
const output = `export const deployer: Uint8Array = new Uint8Array([${byteString}]);\n`; | ||
|
||
fs.writeFileSync(path.join(__dirname, 'deployer-bytecode.ts'), output); | ||
|
||
console.log('Wasm bytecode written to deployer-bytecode.ts'); |
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
57 changes: 57 additions & 0 deletions
57
packages/massa-web3/test/experimental/integration/contracts/main.ts
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,57 @@ | ||
// The entry file of your WebAssembly module. | ||
import { Context, Storage, generateEvent } from '@massalabs/massa-as-sdk' | ||
import { Args, stringToBytes } from '@massalabs/as-types' | ||
|
||
/** | ||
* This function is meant to be called only one time: when the contract is deployed. | ||
* | ||
* @param binaryArgs - Arguments serialized with Args | ||
*/ | ||
export function constructor(binaryArgs: StaticArray<u8>): StaticArray<u8> { | ||
// This line is important. It ensures that this function can't be called in the future. | ||
// If you remove this check, someone could call your constructor function and reset your smart contract. | ||
if (!Context.isDeployingContract()) { | ||
return [] | ||
} | ||
|
||
const argsDeser = new Args(binaryArgs) | ||
const name = argsDeser | ||
.nextString() | ||
.expect('Name argument is missing or invalid') | ||
generateEvent(`Constructor called with name ${name}`) | ||
return [] | ||
} | ||
|
||
/** | ||
* @param _ - not used | ||
* @returns the emitted event serialized in bytes | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export function event(_: StaticArray<u8>): StaticArray<u8> { | ||
const message = "I'm an event!" | ||
generateEvent(message) | ||
return stringToBytes(message) | ||
} | ||
|
||
export function setValueToKey(_args: StaticArray<u8>): void { | ||
const args = new Args(_args) | ||
const key = args.nextString().expect('Key argument is missing or invalid') | ||
const value = args.nextString().expect('Value argument is missing or invalid') | ||
|
||
// event the value | ||
Storage.set(key, value) | ||
|
||
generateEvent(`Set value ${value.toString()} to key ${key.toString()}`) | ||
} | ||
|
||
export function getValueFromKey(_args: StaticArray<u8>): StaticArray<u8> { | ||
const args = new Args(_args) | ||
const key = args.nextString().expect('Key argument is missing or invalid') | ||
const value = Storage.get<string>(key) | ||
return stringToBytes(value) | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
export function sendCoins(_: StaticArray<u8>): void { | ||
const coinAmount = Context.transferredCoins() | ||
generateEvent(`Received ${coinAmount.toString()} coins`) | ||
} |
Binary file added
BIN
+17.7 KB
packages/massa-web3/test/experimental/integration/contracts/main.wasm
Binary file not shown.
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 |
---|---|---|
|
@@ -10,4 +10,5 @@ | |
"node_modules", | ||
"**/*.spec.ts" | ||
] | ||
} | ||
} | ||
|