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(cosmos): Add support for contract call transaction #3691

Merged
merged 1 commit into from
Jun 27, 2023

Conversation

dpkjnr
Copy link
Contributor

@dpkjnr dpkjnr commented Jun 23, 2023

Ticket: WIN-20

@dpkjnr dpkjnr force-pushed the cosmos-contract-txn branch 6 times, most recently from a67fd14 to 9f5715a Compare June 26, 2023 16:53
@dpkjnr dpkjnr marked this pull request as ready for review June 26, 2023 17:49
@dpkjnr dpkjnr requested review from a team as code owners June 26, 2023 17:49
private registry;
constructor() {
this.registry = new Registry([...defaultRegistryTypes]);
this.registry.register('/cosmwasm.wasm.v1.MsgExecuteContract', MsgExecuteContract);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could be a constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should already be there in constants, let me use that here

Comment on lines +7 to +8
export const accountAddressRegex = /^(cosmos)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l']{38})$/;
export const validatorAddressRegex = /^(cosmosvaloper)1(['qpzry9x8gf2tvdw0s3jn54khce6mua7l']{38})$/;
Copy link
Contributor

Choose a reason for hiding this comment

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

What changed here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

length, for account address it would always be 38 character long(excluding prefix)

Comment on lines +20 to +22
isValidContractAddress(address: string): boolean {
return constants.contractAddressRegex.test(address);
}
Copy link
Contributor

@Vijay-Jagannathan Vijay-Jagannathan Jun 26, 2023

Choose a reason for hiding this comment

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

this and few other methods - seems like we could put it together in a parent class after abstracting the regex pattern; not too concerned though

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was also thinking to do that, but it seemed more clean to me, let me check it again

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it can be done but I don't want to delay this PR, will create a separate PR for it after completing wallet platform changes

@@ -129,7 +129,7 @@ export class CosmosCoin extends BaseCoin {
throw new Error('Tx outputs does not match with expected txParams recipients');
}
// WithdrawDelegatorRewards transaction doesn't have amount
if (transaction.type !== TransactionType.StakingWithdraw) {
if (transaction.type !== TransactionType.StakingWithdraw && transaction.type !== TransactionType.ContractCall) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Contract interaction support the amount, anyway that will not require in our case but let's keep in mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, it is under funds and didn't want to update current amount validation for it

* @returns {boolean} - the validation result
*/
isValidContractAddress(address: string): boolean {
throw new NotImplementedError('isValidContractAddress not implemented');
Copy link
Contributor

Choose a reason for hiding this comment

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

let's implement using the length comparison and add ToDo to implement with Regex. Else it will be blocker in the platform side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is there in extended classes

@dpkjnr dpkjnr merged commit 0bd8547 into master Jun 27, 2023

import * as crypto from 'crypto';
import * as constants from './constants';
import {
CosmosLikeTransaction,
DelegateOrUndelegeteMessage,
ExecuteContractMessage,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use CosmosTransactionMessage here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can't, schema is different

@@ -473,19 +501,23 @@ export class CosmosUtils implements BaseUtils {
switch (type) {
case TransactionType.Send: {
const value = messageData.value as SendMessage;
this.isObjPropertyNull(value, ['toAddress', 'fromAddress']);
Copy link
Contributor

Choose a reason for hiding this comment

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

why are we removing this null check ??

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is being done in this.validateSendMessage, I wanted to keep validation code common

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check this function's path - enrichTransactionDetailsFromRawTransaction()
I think we wont be making this null check here. As this is not calling this.validateSendMessage.

break;
}
case TransactionType.StakingWithdraw: {
const value = messageData.value as WithdrawDelegatorRewardsMessage;
this.isObjPropertyNull(value, ['validatorAddress', 'delegatorAddress']);
Copy link
Contributor

Choose a reason for hiding this comment

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

same as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants