mirror of
https://github.com/fluencelabs/aquavm
synced 2024-12-04 15:20:16 +00:00
Pass updated RunParameters to AquaVM (#256)
This commit is contained in:
parent
3f510e1581
commit
f175b31ffd
@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { CallResultsArray, InterpreterResult, CallRequest } from './types';
|
||||
import { CallResultsArray, InterpreterResult, CallRequest, RunParameters } from './types';
|
||||
|
||||
const decoder = new TextDecoder();
|
||||
const encoder = new TextEncoder();
|
||||
@ -30,8 +30,7 @@ const encoder = new TextEncoder();
|
||||
* @returns AVM call arguments as serialized JSON string
|
||||
*/
|
||||
export function serializeAvmArgs(
|
||||
initPeerId: string,
|
||||
currentPeerId: string,
|
||||
runParams: RunParameters,
|
||||
air: string,
|
||||
prevData: Uint8Array,
|
||||
data: Uint8Array,
|
||||
@ -45,11 +44,6 @@ export function serializeAvmArgs(
|
||||
};
|
||||
}
|
||||
|
||||
const paramsToPass = {
|
||||
init_peer_id: initPeerId,
|
||||
current_peer_id: currentPeerId,
|
||||
};
|
||||
|
||||
const encoded = encoder.encode(JSON.stringify(callResultsToPass));
|
||||
|
||||
const avmArg = JSON.stringify([
|
||||
@ -57,7 +51,12 @@ export function serializeAvmArgs(
|
||||
air,
|
||||
Array.from(prevData),
|
||||
Array.from(data),
|
||||
paramsToPass,
|
||||
{
|
||||
init_peer_id: runParams.initPeerId,
|
||||
current_peer_id: runParams.currentPeerId,
|
||||
timestamp: runParams.timestamp,
|
||||
ttl: runParams.ttl,
|
||||
},
|
||||
Array.from(encoded),
|
||||
]);
|
||||
|
||||
@ -149,15 +148,14 @@ type CallToAvm = ((args: string) => Promise<string>) | ((args: string) => string
|
||||
*/
|
||||
export async function callAvm(
|
||||
fn: CallToAvm,
|
||||
initPeerId: string,
|
||||
currentPeerId: string,
|
||||
runParams: RunParameters,
|
||||
air: string,
|
||||
prevData: Uint8Array,
|
||||
data: Uint8Array,
|
||||
callResults: CallResultsArray,
|
||||
): Promise<InterpreterResult> {
|
||||
try {
|
||||
const avmArg = serializeAvmArgs(initPeerId, currentPeerId, air, prevData, data, callResults);
|
||||
const avmArg = serializeAvmArgs(runParams, air, prevData, data, callResults);
|
||||
const rawResult = await fn(avmArg);
|
||||
return deserializeAvmResult(rawResult);
|
||||
} catch (e) {
|
||||
|
@ -16,6 +16,32 @@
|
||||
|
||||
export type LogLevel = 'info' | 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'off';
|
||||
|
||||
/**
|
||||
* Parameters that a host side should pass to an interpreter and that necessary for execution.
|
||||
*/
|
||||
export interface RunParameters {
|
||||
/**
|
||||
* Peer id of a peer that start this particle.
|
||||
*/
|
||||
initPeerId: String;
|
||||
|
||||
/**
|
||||
* Peer id of a current peer.
|
||||
*/
|
||||
currentPeerId: String;
|
||||
|
||||
/**
|
||||
* Unix timestamp from a particle in milliseconds.
|
||||
* It represents time when this particle was sent from the init peer id.
|
||||
*/
|
||||
timestamp: number;
|
||||
|
||||
/**
|
||||
* TTL set by init peer id in milliseconds.
|
||||
*/
|
||||
ttl: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an executed host function result.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user