forked from Agoric/agoric-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref: #33 Note: update /packages/cosmic-proto/dist/helpers.d.ts to the following: export declare const toRequestQueryJson: (msg: QueryBalanceRequestProtoMsg | QueryNFTsRequestProtoMsg, opts?: RequestQueryOpts) => JsonSafe<RequestQuery>;
- Loading branch information
1 parent
f7470aa
commit 7e4a3c3
Showing
2 changed files
with
87 additions
and
0 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,83 @@ | ||
import { M } from '@endo/patterns'; | ||
import { E } from '@endo/far'; | ||
import { TopicsRecordShape } from '@agoric/zoe/src/contractSupport/index.js'; | ||
import { ChainAddressShape, NftShape } from '../typeGuards.js'; | ||
import { | ||
QueryNFTsRequest, | ||
QueryNFTsResponse, | ||
} from '@agoric/cosmic-proto/cosmos/nft/v1beta1/query.js'; | ||
import { toRequestQueryJson } from '@agoric/cosmic-proto'; | ||
import { Fail } from '@agoric/assert'; | ||
import { decodeBase64 } from '@endo/base64'; | ||
|
||
/** | ||
* @param {import('@agoric/zone').Zone} zone | ||
* @param {ZCF} zcf | ||
*/ | ||
export const prepareNftKit = (zone, zcf) => { | ||
const makeNftKit = zone.exoClassKit( | ||
'Nft Account Holder', | ||
{ | ||
helper: M.interface('helper', { | ||
toNftDenomAmount: M.call(M.string()).returns(M.any()), | ||
}), | ||
invitationMakers: M.interface('invitationMakers', { | ||
send: M.call().returns(M.any()), | ||
}), | ||
holder: M.interface('IcaAccountHolder', { | ||
getPublicTopics: M.call().returns(TopicsRecordShape), | ||
getAddress: M.call().returns(ChainAddressShape), | ||
getBalance: M.call(M.string()).returns(NftShape), | ||
getBalances: M.call().returns(M.arrayOf(NftShape)), | ||
}), | ||
}, | ||
/** | ||
* @param {import('../types.js').ChainAddress} chainAddress | ||
* @param {import('../types.js').IcaAccount} account | ||
* @param {import('../types.js').ICQConnection} icqConnection | ||
* @param {string} nftDenom | ||
* @param {StorageNode} storageNode | ||
*/ | ||
(chainAddress, account, icqConnection, nftDenom, storageNode) => { | ||
return { chainAddress, account, icqConnection, nftDenom }; | ||
}, | ||
{ | ||
helper: { | ||
toNftDenomAmount(nft) {}, | ||
}, | ||
|
||
invitationMakers: { | ||
async send(nftAmount, address) {}, | ||
}, | ||
|
||
holder: { | ||
getAddress() { | ||
return this.state.chainAddress; | ||
}, | ||
async getBalance(denom) { | ||
const { toNftDenomAmount } = this.facets.helper; | ||
const { chainAddress, icqConnection, nftDenom } = this.state; | ||
denom ||= nftDenom; | ||
assert.typeof(denom, 'string'); | ||
|
||
const [result] = await E(icqConnection).query([ | ||
toRequestQueryJson( | ||
QueryNFTsRequest.toProtoMsg({ | ||
classId: denom, | ||
owner: chainAddress.address, | ||
}), | ||
), | ||
]); | ||
|
||
if (!result?.key) throw Fail`Error parsing result ${result}`; | ||
const { nfts } = QueryNFTsResponse.decode(decodeBase64(result.key)); | ||
if (!nfts) throw Fail`Result lacked balance key: ${result}`; | ||
|
||
return harden(toNftDenomAmount(nfts)); | ||
}, | ||
async getBalances() {}, | ||
}, | ||
}, | ||
); | ||
return harden({ makeNftKit }); | ||
}; |
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