Skip to content

Commit

Permalink
generate subgraph pubKeyId using maciAddress
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Jun 4, 2024
1 parent 12a4643 commit 07644d2
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 14 deletions.
5 changes: 2 additions & 3 deletions vue-app/src/api/cart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,14 @@ export async function getCommittedCart(
encryptionKey: string,
contributorAddress: string,
): Promise<CartItem[]> {
const { coordinatorPubKey, fundingRoundAddress, voiceCreditFactor, nativeTokenDecimals, recipientRegistryAddress } =
round
const { coordinatorPubKey, maciAddress, voiceCreditFactor, nativeTokenDecimals, recipientRegistryAddress } = round

const encKeypair = await Keypair.createFromSeed(encryptionKey)

const sharedKey = Keypair.genEcdhSharedKey(encKeypair.privKey, coordinatorPubKey)

const messages = await getContributorMessages({
fundingRoundAddress,
maciAddress,
contributorKey: encKeypair,
coordinatorPubKey,
contributorAddress,
Expand Down
11 changes: 5 additions & 6 deletions vue-app/src/api/contributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,28 @@ function getMaciMessage(type: any, data: any[] | null): Message {

/**
* Get the latest set of vote messages submitted by contributor
* @param fundingRoundAddress Funding round contract address
* @param maciAddress MACI contract address
* @param contributorKey Contributor key used to encrypt messages
* @param coordinatorPubKey Coordinator public key
* @returns MACI messages
*/
export async function getContributorMessages({
fundingRoundAddress,
maciAddress,
contributorKey,
coordinatorPubKey,
contributorAddress,
}: {
fundingRoundAddress: string
maciAddress: string
contributorKey: Keypair
coordinatorPubKey: PubKey
contributorAddress: string
}): Promise<Message[]> {
if (!fundingRoundAddress) {
if (!maciAddress) {
return []
}

const key = getPubKeyId(fundingRoundAddress, contributorKey.pubKey)
const key = getPubKeyId(maciAddress, contributorKey.pubKey)
const result = await sdk.GetContributorMessages({
fundingRoundAddress: fundingRoundAddress.toLowerCase(),
pubKey: key,
contributorAddress: contributorAddress.toLowerCase(),
})
Expand Down
5 changes: 2 additions & 3 deletions vue-app/src/graphql/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3147,7 +3147,6 @@ export type GetContributorIndexQueryVariables = Exact<{
export type GetContributorIndexQuery = { __typename?: 'Query', publicKeys: Array<{ __typename?: 'PublicKey', id: string, stateIndex: any | null }> };

export type GetContributorMessagesQueryVariables = Exact<{
fundingRoundAddress: Scalars['String'];
pubKey: Scalars['String'];
contributorAddress: Scalars['Bytes'];
}>;
Expand Down Expand Up @@ -3280,9 +3279,9 @@ export const GetContributorIndexDocument = gql`
}
`;
export const GetContributorMessagesDocument = gql`
query GetContributorMessages($fundingRoundAddress: String!, $pubKey: String!, $contributorAddress: Bytes!) {
query GetContributorMessages($pubKey: String!, $contributorAddress: Bytes!) {
messages(
where: {fundingRound: $fundingRoundAddress, publicKey: $pubKey, submittedBy: $contributorAddress}
where: {publicKey: $pubKey, submittedBy: $contributorAddress}
first: 1000
orderBy: blockNumber
orderDirection: desc
Expand Down
2 changes: 0 additions & 2 deletions vue-app/src/graphql/queries/GetContributorMessages.graphql
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
query GetContributorMessages(
$fundingRoundAddress: String!
$pubKey: String!
$contributorAddress: Bytes!
) {
messages(
where: {
fundingRound: $fundingRoundAddress,
publicKey: $pubKey,
submittedBy: $contributorAddress
},
Expand Down

0 comments on commit 07644d2

Please sign in to comment.