Skip to content

Commit

Permalink
wasmByteCode
Browse files Browse the repository at this point in the history
  • Loading branch information
pyramation committed Jul 20, 2022
1 parent 9164519 commit 72058ae
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ exports[`cosmwasm/wasm/v1/tx MsgStoreCode 1`] = `
}: MsgStoreCode): AminoMsgStoreCode[\\"value\\"] => {
return {
sender,
wasm_byte_code: wasmByteCode,
wasm_byte_code: toBase64(wasmByteCode),
instantiate_permission: {
permission: instantiatePermission.permission,
address: instantiatePermission.address
Expand All @@ -147,7 +147,7 @@ exports[`cosmwasm/wasm/v1/tx MsgStoreCode 1`] = `
}: AminoMsgStoreCode[\\"value\\"]): MsgStoreCode => {
return {
sender,
wasmByteCode: wasm_byte_code,
wasmByteCode: fromBase64(wasm_byte_code),
instantiatePermission: {
permission: accessTypeFromJSON(instantiate_permission.permission),
address: instantiate_permission.address
Expand Down
14 changes: 10 additions & 4 deletions packages/ast/src/encoding/amino/from-amino-json/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,16 @@ export const fromAminoParseField = ({
return fromAmino.enum(args);
}

// bytes [RawContractMessage]
if (field.type === 'bytes' &&
field.options?.['(gogoproto.casttype)'] === 'RawContractMessage') {
return fromAmino.rawBytes(args);
if (field.type === 'bytes') {
// bytes [RawContractMessage]
if (field.options?.['(gogoproto.casttype)'] === 'RawContractMessage') {
return fromAmino.rawBytes(args);
}
// bytes [WASMByteCode]
// TODO use a better option for this in proto source
if (field.options?.['(gogoproto.customname)'] === 'WASMByteCode') {
return fromAmino.wasmByteCode(args);
}
}

// scalar types...
Expand Down
13 changes: 13 additions & 0 deletions packages/ast/src/encoding/amino/from-amino-json/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ export const fromAmino = {
);
},

wasmByteCode(args: FromAminoParseField) {
args.context.addUtil('fromBase64');
return t.objectProperty(
t.identifier(args.field.name),
t.callExpression(
t.identifier('fromBase64'),
[
memberExpressionOrIdentifierAminoCaseField(args.fieldPath, args.context.aminoCaseField)
]
)
);
},

long(args: FromAminoParseField) {
args.context.addUtil('Long');

Expand Down
14 changes: 10 additions & 4 deletions packages/ast/src/encoding/amino/to-amino-json/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,16 @@ export const toAminoParseField = ({
return toAmino.type(args);
}

// bytes [RawContractMessage]
if (field.type === 'bytes' &&
field.options?.['(gogoproto.casttype)'] === 'RawContractMessage') {
return toAmino.rawBytes(args);
if (field.type === 'bytes') {
// bytes [RawContractMessage]
if (field.options?.['(gogoproto.casttype)'] === 'RawContractMessage') {
return toAmino.rawBytes(args);
}
// bytes [WASMByteCode]
// TODO use a better option for this in proto source
if (field.options?.['(gogoproto.customname)'] === 'WASMByteCode') {
return toAmino.wasmByteCode(args);
}
}

// scalar types...
Expand Down
14 changes: 14 additions & 0 deletions packages/ast/src/encoding/amino/to-amino-json/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ export const toAmino = {
);
},

wasmByteCode(args: ToAminoParseField) {
args.context.addUtil('toBase64');
return t.objectProperty(
t.identifier(args.context.aminoCaseField(args.field)),
t.callExpression(
t.identifier('toBase64'),
[
memberExpressionOrIdentifier(args.scope)
]
)

);
},

duration(args: ToAminoParseField) {
const exp = t.binaryExpression(
'*',
Expand Down

0 comments on commit 72058ae

Please sign in to comment.