Skip to content

Commit

Permalink
feat: wip allow the initial state to be stored as MsgPack binary
Browse files Browse the repository at this point in the history
  • Loading branch information
noomly committed Dec 19, 2022
1 parent 44d73b8 commit 8355d89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/contract/deploy/CreateContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const emptyTransfer: ArTransfer = {

export interface CommonContractData {
wallet: ArWallet | SignatureType;
initState: string;
initState: string | Buffer;
tags?: Tags;
transfer?: ArTransfer;
data?: {
Expand Down
5 changes: 4 additions & 1 deletion src/contract/deploy/impl/DefaultCreateContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export class DefaultCreateContract implements CreateContract {
contractTX.addTag(SmartWeaveTags.SDK, 'RedStone');
if (data) {
contractTX.addTag(SmartWeaveTags.CONTENT_TYPE, data['Content-Type']);
contractTX.addTag(SmartWeaveTags.INIT_STATE, initState);
contractTX.addTag(
SmartWeaveTags.INIT_STATE,
typeof initState === 'string' ? initState : new TextDecoder().decode(initState)
);
} else {
contractTX.addTag(SmartWeaveTags.CONTENT_TYPE, 'application/json');
}
Expand Down
8 changes: 5 additions & 3 deletions src/core/modules/impl/ContractDefinitionLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { TagsParser } from './TagsParser';
import { WasmSrc } from './wasm/WasmSrc';
import { WarpEnvironment } from '../../Warp';
import { SortKeyCache } from 'cache/SortKeyCache';
import { unpack } from 'msgpackr';

const supportedSrcContentTypes = ['application/javascript', 'application/wasm'];

Expand Down Expand Up @@ -55,9 +56,10 @@ export class ContractDefinitionLoader implements DefinitionLoader {
const minFee = this.tagsParser.getTag(contractTx, SmartWeaveTags.MIN_FEE);
this.logger.debug('Tags decoding', benchmark.elapsed());
benchmark.reset();
const s = await this.evalInitialState(contractTx);
this.logger.debug('init state', s);
const initState = JSON.parse(await this.evalInitialState(contractTx));
// TODO: It should be stored somewhere whether the initial state is stored as a JSON string or
// as a MsgPack binary. For the sake of this experiment, we assume it's always MsgPack.
// const initState = JSON.parse(await this.evalInitialState(contractTx));
const initState = unpack(await this.arweaveWrapper.txData(contractTx.id));
this.logger.debug('Parsing src and init state', benchmark.elapsed());

const { src, srcBinary, srcWasmLang, contractType, metadata, srcTx } = await this.loadContractSource(
Expand Down

0 comments on commit 8355d89

Please sign in to comment.