Add ContractMigrationAuthorization
This commit is contained in:
parent
9e63aba259
commit
eb1a448896
@ -14,6 +14,7 @@ import {
|
||||
AllowAllMessagesFilter,
|
||||
CombinedLimit,
|
||||
ContractExecutionAuthorization,
|
||||
ContractMigrationAuthorization,
|
||||
MaxCallsLimit,
|
||||
MaxFundsLimit,
|
||||
} from 'cosmjs-types/cosmwasm/wasm/v1/authz'
|
||||
@ -68,7 +69,8 @@ export function AuthzSendGrantMsg(
|
||||
denom,
|
||||
}),
|
||||
],
|
||||
//allowList,
|
||||
// Needs cosmos-sdk >= 0.47
|
||||
// allowList,
|
||||
}),
|
||||
).finish()
|
||||
|
||||
@ -165,6 +167,81 @@ export function AuthzExecuteContractGrantMsg(
|
||||
}
|
||||
}
|
||||
|
||||
export function AuthzMigrateContractGrantMsg(
|
||||
granter: string,
|
||||
grantee: string,
|
||||
contract: string,
|
||||
expiration: number,
|
||||
callsRemaining?: number,
|
||||
amounts?: Coin[],
|
||||
allowedMessages?: string[],
|
||||
): Msg {
|
||||
const sendAuthValue = ContractMigrationAuthorization.encode(
|
||||
ContractMigrationAuthorization.fromPartial({
|
||||
grants: [
|
||||
{
|
||||
contract,
|
||||
filter: {
|
||||
typeUrl: allowedMessages
|
||||
? '/cosmwasm.wasm.v1.AcceptedMessageKeysFilter'
|
||||
: '/cosmwasm.wasm.v1.AllowAllMessagesFilter',
|
||||
value: allowedMessages
|
||||
? AcceptedMessageKeysFilter.encode({ keys: allowedMessages }).finish()
|
||||
: AllowAllMessagesFilter.encode({}).finish(),
|
||||
},
|
||||
limit:
|
||||
callsRemaining || amounts
|
||||
? {
|
||||
typeUrl:
|
||||
callsRemaining && amounts
|
||||
? '/cosmwasm.wasm.v1.CombinedLimit'
|
||||
: callsRemaining
|
||||
? '/cosmwasm.wasm.v1.MaxCallsLimit'
|
||||
: '/cosmwasm.wasm.v1.MaxFundsLimit',
|
||||
value:
|
||||
callsRemaining && amounts
|
||||
? CombinedLimit.encode({
|
||||
callsRemaining: BigInt(callsRemaining),
|
||||
amounts,
|
||||
}).finish()
|
||||
: callsRemaining
|
||||
? MaxCallsLimit.encode({
|
||||
remaining: BigInt(callsRemaining),
|
||||
}).finish()
|
||||
: MaxFundsLimit.encode({
|
||||
amounts: amounts || [],
|
||||
}).finish(),
|
||||
}
|
||||
: {
|
||||
// limit: undefined is not accepted
|
||||
typeUrl: '/cosmwasm.wasm.v1.MaxCallsLimit',
|
||||
value: MaxCallsLimit.encode({
|
||||
remaining: BigInt(100000),
|
||||
}).finish(),
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
).finish()
|
||||
|
||||
const grantValue = MsgGrant.fromPartial({
|
||||
grant: {
|
||||
authorization: {
|
||||
typeUrl: '/cosmwasm.wasm.v1.ContractMigrationAuthorization',
|
||||
value: sendAuthValue,
|
||||
},
|
||||
expiration: expiration ? { seconds: BigInt(expiration), nanos: 0 } : undefined,
|
||||
},
|
||||
grantee,
|
||||
granter,
|
||||
})
|
||||
|
||||
return {
|
||||
typeUrl: msgAuthzGrantTypeUrl,
|
||||
value: grantValue,
|
||||
}
|
||||
}
|
||||
|
||||
export function AuthzGenericGrantMsg(granter: string, grantee: string, typeURL: string, expiration: number): Msg {
|
||||
return {
|
||||
typeUrl: msgAuthzGrantTypeUrl,
|
||||
|
@ -18,7 +18,12 @@ import { LinkTabs } from 'components/LinkTabs'
|
||||
import { authzLinkTabs } from 'components/LinkTabs.data'
|
||||
import { getConfig } from 'config'
|
||||
import type { Msg } from 'config/authz'
|
||||
import { AuthzExecuteContractGrantMsg, AuthzGenericGrantMsg, AuthzSendGrantMsg } from 'config/authz'
|
||||
import {
|
||||
AuthzExecuteContractGrantMsg,
|
||||
AuthzGenericGrantMsg,
|
||||
AuthzMigrateContractGrantMsg,
|
||||
AuthzSendGrantMsg,
|
||||
} from 'config/authz'
|
||||
import { useGlobalSettings } from 'contexts/globalSettings'
|
||||
import type { NextPage } from 'next'
|
||||
import { NextSeo } from 'next-seo'
|
||||
@ -217,6 +222,16 @@ const Grant: NextPage = () => {
|
||||
maxFundsLimitState.value > 0 ? coins(maxFundsLimitState.value, maxFundsLimitDenomState.value) : undefined,
|
||||
allowedMessageKeysState.value ? allowedMessageKeysState.value.split(',').map((key) => key.trim()) : undefined,
|
||||
)
|
||||
} else if (authType === 'Migrate Smart Contract') {
|
||||
return AuthzMigrateContractGrantMsg(
|
||||
wallet.address || '',
|
||||
granteeAddressState.value,
|
||||
contractAddressState.value,
|
||||
(expiration?.getTime() as number) / 1000 || 0,
|
||||
callsRemainingState.value ? callsRemainingState.value : undefined,
|
||||
maxFundsLimitState.value > 0 ? coins(maxFundsLimitState.value, maxFundsLimitDenomState.value) : undefined,
|
||||
allowedMessageKeysState.value ? allowedMessageKeysState.value.split(',').map((key) => key.trim()) : undefined,
|
||||
)
|
||||
}
|
||||
}
|
||||
const handleSendMessage = async () => {
|
||||
@ -260,9 +275,7 @@ const Grant: NextPage = () => {
|
||||
<option value="Generic">Generic</option>
|
||||
<option value="Send">Send</option>
|
||||
<option value="Execute Smart Contract">Execute Smart Contract</option>
|
||||
<option disabled value="Migrate Smart Contract">
|
||||
Migrate Smart Contract
|
||||
</option>
|
||||
<option value="Migrate Smart Contract">Migrate Smart Contract</option>
|
||||
</select>
|
||||
</div>
|
||||
<Conditional test={authType === 'Generic'}>
|
||||
@ -291,9 +304,10 @@ const Grant: NextPage = () => {
|
||||
<NumberInput className="w-1/4" {...spendLimitState} />
|
||||
<TextInput className="w-1/4 ml-2" {...spendLimitDenomState} />
|
||||
</div>
|
||||
{/* Needs cosmos-sdk v0.47 */}
|
||||
{/* <TextInput className="w-2/5" {...allowListState} /> */}
|
||||
</Conditional>
|
||||
<Conditional test={authType === 'Execute Smart Contract'}>
|
||||
<Conditional test={authType === 'Execute Smart Contract' || authType === 'Migrate Smart Contract'}>
|
||||
<AddressInput className="w-2/5" {...contractAddressState} />
|
||||
<TextInput className="w-2/5" {...allowedMessageKeysState} />
|
||||
<NumberInput className="w-2/5" {...callsRemainingState} />
|
||||
|
Loading…
Reference in New Issue
Block a user