-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Feegrant * feat: Feegrant * Create angry-horses-enjoy.md
- Loading branch information
Showing
9 changed files
with
252 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@demo/wallet": patch | ||
"@bnb-chain/greenfield-chain-sdk": patch | ||
--- | ||
|
||
feat: Feegrant `grantAllowance` API |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { client, selectSp } from '@/client'; | ||
import { GRNToString, newBucketGRN, PermissionTypes } from '@bnb-chain/greenfield-chain-sdk'; | ||
import { Wallet } from '@ethersproject/wallet'; | ||
import { useState } from 'react'; | ||
import { useAccount, useNetwork } from 'wagmi'; | ||
|
||
export const FeeGrant = () => { | ||
const { address } = useAccount(); | ||
const [bucketName, setBucketName] = useState<string>(''); | ||
|
||
return ( | ||
<> | ||
<h4>Feegrant</h4> | ||
bucket name : | ||
<input | ||
value={bucketName} | ||
placeholder="bucket name" | ||
onChange={(e) => { | ||
setBucketName(e.target.value); | ||
}} | ||
/> | ||
<br /> | ||
<button | ||
onClick={async () => { | ||
if (!address) return; | ||
|
||
// select sp to be primary sp | ||
const spInfo = await selectSp(); | ||
const { primarySpAddress } = spInfo; | ||
|
||
/* await client.bucket.createBucket({ | ||
bucketName, | ||
creator: address, | ||
visibility: 'VISIBILITY_TYPE_PUBLIC_READ', | ||
chargedReadQuota: '0', | ||
spInfo, | ||
signType: 'authTypeV2', | ||
}); */ | ||
|
||
const { sequence } = await client.account.getAccount(address); | ||
console.log('sequence', sequence); | ||
|
||
const wallet = Wallet.createRandom(); | ||
console.log('wallet', wallet, wallet.privateKey); | ||
|
||
const grantAllowanceTx = await client.feegrant.grantAllowance({ | ||
granter: address, | ||
grantee: wallet.address, | ||
// allowance: , | ||
}); | ||
|
||
const simulateInfo = await grantAllowanceTx.simulate({ | ||
denom: 'BNB', | ||
}); | ||
|
||
console.log('simulateInfo:', simulateInfo); | ||
|
||
const res = await grantAllowanceTx.broadcast({ | ||
denom: 'BNB', | ||
gasLimit: Number(simulateInfo?.gasLimit), | ||
gasPrice: simulateInfo?.gasPrice || '5000000000', | ||
payer: address, | ||
granter: '', | ||
}); | ||
|
||
console.log(res); | ||
|
||
// const statement: PermissionTypes.Statement = { | ||
// effect: PermissionTypes.Effect.EFFECT_ALLOW, | ||
// actions: [PermissionTypes.ActionType.ACTION_UPDATE_BUCKET_INFO], | ||
// resources: [GRNToString(newBucketGRN(bucketName))], | ||
// }; | ||
// const putPolicyTx = await client.bucket.putBucketPolicy(bucketName, { | ||
// operator: address, | ||
// statements: [statement], | ||
// principal: { | ||
// type: PermissionTypes.PrincipalType.PRINCIPAL_TYPE_GNFD_ACCOUNT, | ||
// value: '0x0000000000000000000000000000000000000001', | ||
// }, | ||
// }); | ||
}} | ||
> | ||
go batch | ||
</button> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// import { AllowedMsgAllowance } from '@bnb-chain/greenfield-cosmos-types/cosmos/feegrant/v1beta1/feegrant'; | ||
// import { Any } from '@bnb-chain/greenfield-cosmos-types/google/protobuf/any'; | ||
|
||
// const myAny: Any = { | ||
// typeUrl: '/cosmos.feegrant.v1beta1.MsgAllowance', | ||
// // value: | ||
// }; | ||
|
||
// const x: AllowedMsgAllowance = { | ||
// allowedMessages: [], | ||
// allowance: myAny, | ||
// }; | ||
|
||
// export const NewAllowedMsgAllowance = ( | ||
// allowance: any, | ||
// allowedMsgs: string[], | ||
// ): AllowedMsgAllowance => {}; |
Oops, something went wrong.