Skip to content

Commit

Permalink
refactored MsgGrant type to cosmjs
Browse files Browse the repository at this point in the history
  • Loading branch information
baktun14 committed Sep 12, 2023
1 parent 70d9a42 commit 29c83c4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 41 deletions.
6 changes: 4 additions & 2 deletions deploy-web/src/queries/useGrantsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ async function getGranteeGrants(apiEndpoint: string, address: string) {
const response = await axios.get(ApiUrlService.granteeGrants(apiEndpoint, address));
const filteredGrants = response.data.grants.filter(
x =>
x.authorization["@type"] === "/akash.deployment.v1beta2.DepositDeploymentAuthorization" ||
// TODO: this is not working
// Only the v1beta3 authorization are working
// x.authorization["@type"] === "/akash.deployment.v1beta2.DepositDeploymentAuthorization" ||
x.authorization["@type"] === "/akash.deployment.v1beta3.DepositDeploymentAuthorization"
);

Expand Down Expand Up @@ -78,4 +80,4 @@ export function useAllowancesGranted(address: string, options = {}) {
const { settings } = useSettings();

return useQuery(QueryKeys.getAllowancesGranted(address), () => getAllowancesGranted(settings.apiEndpoint, address), options);
}
}
27 changes: 15 additions & 12 deletions deploy-web/src/utils/TransactionMessageData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { networkVersion } from "./constants";
import { BidDto } from "@src/types/deployment";
import { BasicAllowance, MsgGrantAllowance, MsgRevokeAllowance } from "./proto/grant";
import { BasicAllowance, MsgGrant, MsgGrantAllowance, MsgRevoke, MsgRevokeAllowance } from "./proto/grant";
import { longify } from "@cosmjs/stargate/build/queryclient";
import { protoTypes } from "./proto";

export function setMessageTypes() {
TransactionMessageData.Types.MSG_CLOSE_DEPLOYMENT = `/akash.deployment.${networkVersion}.MsgCloseDeployment`;
Expand Down Expand Up @@ -162,20 +163,22 @@ export class TransactionMessageData {
}

static getGrantMsg(granter: string, grantee: string, spendLimit: number, expiration: Date, denom: string) {
const message = {
const grantMsg = {
typeUrl: TransactionMessageData.Types.MSG_GRANT,
value: {
granter: granter,
grantee: grantee,
grant: {
authorization: {
type_url: TransactionMessageData.Types.MSG_DEPOSIT_DEPLOYMENT_AUTHZ,
value: {
spend_limit: {
denom: denom,
amount: spendLimit.toString()
}
}
typeUrl: TransactionMessageData.Types.MSG_DEPOSIT_DEPLOYMENT_AUTHZ,
value: protoTypes.DepositDeploymentAuthorization.encode(
protoTypes.DepositDeploymentAuthorization.fromPartial({
spendLimit: {
denom: denom,
amount: spendLimit.toString()
}
})
).finish()
},
expiration: {
seconds: Math.floor(expiration.getTime() / 1_000), // Convert milliseconds to seconds
Expand All @@ -185,7 +188,7 @@ export class TransactionMessageData {
}
};

return message;
return grantMsg;
}

static getRevokeMsg(granter: string, grantee: string, grantType: string) {
Expand All @@ -194,11 +197,11 @@ export class TransactionMessageData {

const message = {
typeUrl: TransactionMessageData.Types.MSG_REVOKE,
value: {
value: MsgRevoke.fromPartial({
granter: granter,
grantee: grantee,
msgTypeUrl: msgTypeUrl
}
})
};

return message;
Expand Down
3 changes: 1 addition & 2 deletions deploy-web/src/utils/customRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Registry } from "@cosmjs/proto-signing";
import { MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { MsgRevoke } from "cosmjs-types/cosmos/authz/v1beta1/tx";
import { protoTypes } from "./proto";
import { TransactionMessageData } from "./TransactionMessageData";
import { MsgGrant, MsgGrantAllowance, MsgRevokeAllowance } from "./proto/grant";
import { MsgGrant, MsgRevoke, MsgGrantAllowance, MsgRevokeAllowance } from "./proto/grant";

export let customRegistry: Registry;

Expand Down
26 changes: 1 addition & 25 deletions deploy-web/src/utils/proto/grant.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,3 @@
import { Field, Type } from "protobufjs";
export { MsgGrantAllowance, MsgRevokeAllowance } from "cosmjs-types/cosmos/feegrant/v1beta1/tx";
export { BasicAllowance, PeriodicAllowance, AllowedMsgAllowance } from "cosmjs-types/cosmos/feegrant/v1beta1/feegrant";

// TODO: Find a solution to the MsgGrant proto type not working from cosmjs-types

const Coin = new Type("Coin").add(new Field("denom", 1, "string")).add(new Field("amount", 2, "string"));

const Authorization = new Type("Authorization").add(Coin).add(new Field("spend_limit", 1, "Coin"));

const AnyGrantDeposit = new Type("AnyGrantDeposit")
.add(new Field("type_url", 1, "string"))
.add(new Field("value", 2, "Authorization"))
.add(Authorization);

const Timestamp = new Type("Timestamp").add(new Field("seconds", 1, "uint64")).add(new Field("nanos", 2, "uint32"));
const Grant = new Type("Grant")
.add(new Field("authorization", 1, "AnyGrantDeposit"))
.add(AnyGrantDeposit)
.add(new Field("expiration", 2, "Timestamp"))
.add(Timestamp);

export const MsgGrant = new Type("MsgGrant")
.add(new Field("granter", 1, "string"))
.add(new Field("grantee", 2, "string"))
.add(new Field("grant", 3, "Grant"))
.add(Grant);
export { MsgGrant, MsgRevoke } from "cosmjs-types/cosmos/authz/v1beta1/tx";

0 comments on commit 29c83c4

Please sign in to comment.