Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Define and create new handler for new vm_noop message type #540

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/adena-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
"webpack-merge": "^5.10.0"
},
"dependencies": {
"@gnolang/gno-js-client": "1.3.0",
"@gnolang/tm2-js-client": "1.2.1",
"@gnolang/gno-js-client": "git+https://github.com/VAR-META-Tech/gno-js-client.git#msg_noop",
"@gnolang/tm2-js-client": "git+https://github.com/VAR-META-Tech/tm2-js-client.git#msg_noop",
"@tanstack/react-query": "^4.36.1",
"@vespaiach/axios-fetch-adapter": "^0.3.1",
"adena-module": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,19 @@ export const validateTransactionMessageOfRun = (message: { [key in string]: any
}
return true;
};

export const validateTransactionMessageOfVmNoop = (message: { [key in string]: any }): boolean => {
if (!message.type || !message.value) {
return false;
}
if (message.type !== '/vm.m_noop') {
return false;
}
if (typeof message.value !== 'object') {
return false;
}
if (Object.keys(message.value).indexOf('caller') === -1) {
return false;
}
return true;
};
6 changes: 6 additions & 0 deletions packages/adena-extension/src/inject/executor/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
validateTransactionMessageOfBankSend,
validateTransactionMessageOfRun,
validateTransactionMessageOfVmCall,
validateTransactionMessageOfVmNoop,
} from '@common/validation/validation-message';

type Params = { [key in string]: any };
Expand Down Expand Up @@ -133,6 +134,11 @@ export class AdenaExecutor {
return InjectionMessageInstance.failure('INVALID_FORMAT');
}
break;
case '/vm.m_noop':
if (!validateTransactionMessageOfVmNoop(message)) {
return InjectionMessageInstance.failure('INVALID_FORMAT');
}
break;
default:
return InjectionMessageInstance.failure('UNSUPPORTED_TYPE');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export const validateInjectionAddress = (currentAccountAddress: string): boolean
};

export const validateInjectionTransactionType = (requestData: InjectionMessage): any => {
const messageTypes = ['/bank.MsgSend', '/vm.m_call', '/vm.m_addpkg', '/vm.m_run'];
const messageTypes = ['/bank.MsgSend', '/vm.m_call', '/vm.m_addpkg', '/vm.m_run', '/vm.m_noop'];
return requestData.data?.messages.every((message: any) => messageTypes.includes(message?.type));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,14 @@ const ApproveTransactionContainer: React.FC = () => {
};
}, [document]);

const isSponsorService = useMemo(() => {
return (document?.msgs?.length ?? 0) > 1 && document?.msgs[0].type === '/vm.m_noop';
}, [document]);

const isErrorNetworkFee = useMemo(() => {
if (isSponsorService) {
return false;
}
return BigNumber(currentBalance).shiftedBy(-6).isLessThan(networkFee.amount);
}, [currentBalance, networkFee]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
HistoryItemBankMsgSend,
HistoryItemVmMAddPkg,
HistoryItemVmMCall,
HistoryItemVmMNoop,
TransactionHistoryResponse,
} from '../response/transaction-history-response';

Expand Down Expand Up @@ -53,6 +54,10 @@ function isHistoryItemVmMAddPkg(historyItem: HistoryItem): historyItem is Histor
return historyItem.type === '/vm.m_addpkg';
}

function isHistoryItemVmMNoop(historyItem: HistoryItem): historyItem is HistoryItemVmMNoop {
return historyItem.type === '/vm.m_noop';
}

function isVmAddPkgType(func?: string): boolean {
return func === 'AddPkg';
}
Expand Down Expand Up @@ -113,6 +118,9 @@ export class TransactionHistoryMapper {
if (isHistoryItemVmMAddPkg(historyItem)) {
return TransactionHistoryMapper.mappedHistoryItemVmMAddPkg(historyItem);
}
if (isHistoryItemVmMNoop(historyItem)) {
return TransactionHistoryMapper.mappedHistoryItemVmMNoop(historyItem);
}
return TransactionHistoryMapper.mappedHistoryItemDefault(historyItem);
}

Expand Down Expand Up @@ -221,6 +229,29 @@ export class TransactionHistoryMapper {
};
}

private static mappedHistoryItemVmMNoop(historyItem: HistoryItemVmMNoop): TransactionInfo {
const { hash, result, func, transfer, date, fee } = historyItem;
const valueType = result.status === 'Fail' ? 'BLUR' : func === 'Receive' ? 'ACTIVE' : 'DEFAULT';
return {
hash,
logo: '',
type: 'CONTRACT_CALL',
typeName: 'Msg for sponsor service',
status: result.status === 'Success' ? 'SUCCESS' : 'FAIL',
title: func ?? '',
amount: {
value: `${transfer.amount || '0'}`,
denom: transfer.denom || 'GNOT',
},
valueType,
date: dateToLocal(date).value,
networkFee: {
value: `${fee.amount || '0'}`,
denom: `${fee.denom}`,
},
};
}

private static mappedHistoryItemDefault(historyItem: HistoryItem): TransactionInfo {
const { hash, result, func, transfer, date, fee } = historyItem;
const valueType = result.status === 'Fail' ? 'BLUR' : func === 'Receive' ? 'ACTIVE' : 'DEFAULT';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ export interface HistoryItemVmMAddPkg extends HistoryItem {
}[];
};
}

export interface HistoryItemVmMNoop extends HistoryItem {
caller: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,17 @@ export const createMessageOfVmRun = (info: {
},
};
};

export const createMessageOfVmNoop = (info: {
caller: string;
}): {
type: string;
value: { caller: string;};
} => {
return {
type: '/vm.m_noop',
value: {
caller: info.caller,
},
};
};
4 changes: 2 additions & 2 deletions packages/adena-module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
},
"dependencies": {
"@cosmjs/ledger-amino": "^0.32.4",
"@gnolang/gno-js-client": "1.3.0",
"@gnolang/tm2-js-client": "1.2.1",
"@gnolang/gno-js-client": "git+https://github.com/VAR-META-Tech/gno-js-client.git#msg_noop",
"@gnolang/tm2-js-client": "git+https://github.com/VAR-META-Tech/tm2-js-client.git#msg_noop",
"@ledgerhq/hw-transport": "^6.30.4",
"@ledgerhq/hw-transport-mocker": "^6.28.4",
"@ledgerhq/hw-transport-webhid": "^6.28.4",
Expand Down
20 changes: 19 additions & 1 deletion packages/adena-module/src/utils/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Any, PubKeySecp256k1, Tx, TxFee, TxSignature } from '@gnolang/tm2-js-client';
import { MsgCall, MsgAddPackage, MsgSend, MsgEndpoint } from '@gnolang/gno-js-client';
import { MsgCall, MsgAddPackage, MsgSend, MsgEndpoint, MsgNoop } from '@gnolang/gno-js-client';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a link to see what MsgNoop looks like?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jinoosss we have PRs 2209 2630 are about MsgNoop. Hope this will give you a clearer view.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can guess from the modifications in the gno chain.
But I wanted to check out decoding the proto in gno-js-client.
https://github.com/onbloc/adena-wallet/pull/540/files#diff-ebc97186e74851cee33a3481a356d0f5e231df2e90af1ccaf35ea14cc9fb461aR63-R64

Copy link
Author

@thinhnx-var thinhnx-var Jul 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for this lately response, it was in pending state, I did not commited the comments

@jinoosss
I think this PR about our changes in gno-js-client may fit.
gnolang/gno-js-client#140
I will update later for further information.

import { MemPackage, MemFile, MsgRun } from '@gnolang/gno-js-client/bin/proto/gno/vm';
import { fromBase64 } from '../encoding';

Expand Down Expand Up @@ -59,6 +59,14 @@ export const decodeTxMessages = (messages: Any[]): any[] => {
...messageJson,
};
}
case MsgEndpoint.MSG_NOOP: {
const decodedMessage = MsgNoop.decode(m.value);
const messageJson = MsgNoop.toJSON(decodedMessage) as any;
return {
'@type': m.typeUrl,
...messageJson,
};
}
default:
throw new Error(`unsupported message type ${m.typeUrl}`);
}
Expand Down Expand Up @@ -128,6 +136,16 @@ function encodeMessageValue(message: { type: string; value: any }) {
value: MsgRun.encode(msgRun).finish(),
});
}
case MsgEndpoint.MSG_NOOP: {
const value = message.value;
const result = MsgNoop.create({
caller: value.caller,
});
return Any.create({
typeUrl: MsgEndpoint.MSG_NOOP,
value: MsgNoop.encode(result).finish(),
});
}
default: {
return Any.create({
typeUrl: MsgEndpoint.MSG_CALL,
Expand Down
Loading