Skip to content

Commit

Permalink
fix: PutPolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 committed Sep 8, 2023
1 parent 18c37d0 commit 33c8f12
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/violet-pillows-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

fix: PutPolicy if resource is empty use `[]` not `['']`
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const GroupPolicy = () => {
const statement: PermissionTypes.Statement = {
effect: PermissionTypes.Effect.EFFECT_ALLOW,
actions: [PermissionTypes.ActionType.ACTION_UPDATE_GROUP_MEMBER],
resources: [''],
resources: [],
};

const tx = await client.group.putGroupPolicy(address, policyGroupInfo.groupName, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const ObjectPolicy = () => {
const statement: PermissionTypes.Statement = {
effect: PermissionTypes.Effect.EFFECT_ALLOW,
actions: [PermissionTypes.ActionType.ACTION_GET_OBJECT],
resources: [''],
resources: [],
};

const tx = await client.object.putObjectPolicy(
Expand Down
30 changes: 23 additions & 7 deletions packages/chain-sdk/src/messages/greenfield/storage/MsgPutPolicy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
export const MsgPutPolicySDKTypeEIP712 = {
import type { EIP712Msg } from '@/messages/utils';
import cloneDeep from 'lodash.clonedeep';

export const getMsgPutPolicySDKTypeEIP712 = (resource: string[]) => {
const res: EIP712Msg = cloneDeep(MsgPutPolicySDKTypeEIP712);

if (resource.length !== 0) {
res.TypeMsg1Statements.push({
name: 'resources',
type: 'string[]',
});
}

return res;
};

const MsgPutPolicySDKTypeEIP712 = {
Msg1: [
{
name: 'type',
Expand Down Expand Up @@ -36,21 +52,21 @@ export const MsgPutPolicySDKTypeEIP712 = {
},
],
TypeMsg1Statements: [
{
name: 'effect',
type: 'string',
},
{
name: 'actions',
type: 'string[]',
},
{
name: 'resources',
type: 'string[]',
name: 'effect',
type: 'string',
},
{
name: 'expiration_time',
type: 'string',
},
// {
// name: 'resources',
// type: 'string[]',
// },
],
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { EIP712Msg } from '@/messages/utils';
import { MsgGroupMember } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/tx';
import cloneDeep from 'lodash.clonedeep';

Expand All @@ -8,9 +9,7 @@ export const getMsgUpdateGroupMemberSDKTypeEIP712 = ({
membersToAdd: MsgGroupMember[];
membersToDelete: string[];
}) => {
const res: Record<string, Array<{ type: string; name: string }>> = cloneDeep(
MsgUpdateGroupMemberSDKTypeEIP712,
);
const res: EIP712Msg = cloneDeep(MsgUpdateGroupMemberSDKTypeEIP712);

if (membersToAdd.length > 0) {
res.Msg1.push({
Expand Down
2 changes: 2 additions & 0 deletions packages/chain-sdk/src/messages/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import mapValues from 'lodash.mapvalues';
import sortBy from 'lodash.sortby';
import { MetaTxInfo } from '..';

export type EIP712Msg = Record<string, Array<{ type: string; name: string }>>;

export const typeWrapper = (type: string, msg: object) => {
return {
...msg,
Expand Down

0 comments on commit 33c8f12

Please sign in to comment.