Skip to content

Commit

Permalink
Feat: Add create event details to colony model
Browse files Browse the repository at this point in the history
Feat: Add create event details to colony model
  • Loading branch information
mmioana committed Dec 13, 2024
1 parent 6b1d83e commit 9f9904a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
16 changes: 15 additions & 1 deletion apps/main-chain/src/handlers/colonies/colonyAdded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getColonyContributorId } from '~utils/contributors';
import { tryFetchGraphqlQuery } from '~utils/graphql';
import { createUniqueColony } from './helpers/createUniqueColony';
import { output } from '@joincolony/utils';
import rpcProvider from '~provider';

export default async (event: ContractEvent): Promise<void> => {
const { transactionHash, args, blockNumber } = event;
Expand Down Expand Up @@ -77,6 +78,16 @@ export default async (event: ContractEvent): Promise<void> => {
args: { user: '' },
};

let signerAddress = '';
try {
const transaction = await rpcProvider
.getProviderInstance()
.getTransaction(transactionHash);
signerAddress = transaction.from;
} catch (error) {
// Most likely there was an error retrieving this transaction
}

try {
/*
* Create the colony entry in the database
Expand All @@ -86,7 +97,10 @@ export default async (event: ContractEvent): Promise<void> => {
tokenAddress: utils.getAddress(tokenAddress),
transactionHash,
initiatorAddress: utils.getAddress(colonyFounderAddress),
createdAtBlock: blockNumber,
colonyCreateEvent: {
blockNumber,
signerAddress,
},
});
} catch (error) {
console.error(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
GetTokenFromEverywhereDocument,
GetTokenFromEverywhereQuery,
GetTokenFromEverywhereQueryVariables,
ColonyCreateEvent,
} from '@joincolony/graphql';
import rpcProvider from '~provider';
import { getCachedColonyClient } from '~utils/clients/colony';
Expand All @@ -47,13 +48,13 @@ export const createUniqueColony = async ({
tokenAddress,
transactionHash,
initiatorAddress,
createdAtBlock,
colonyCreateEvent,
}: {
colonyAddress: string;
tokenAddress: string;
transactionHash: string;
initiatorAddress: string;
createdAtBlock: number;
colonyCreateEvent: ColonyCreateEvent;
}): Promise<void> => {
/*
* Validate Colony and Token addresses
Expand Down Expand Up @@ -217,7 +218,7 @@ export const createUniqueColony = async ({
chainMetadata: {
chainId,
},
createdAtBlock,
colonyCreateEvent,
version: version.toNumber(),
status: {
nativeToken: {
Expand Down
24 changes: 17 additions & 7 deletions packages/graphql/src/generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ export type Colony = {
chainFundsClaim?: Maybe<ColonyChainFundsClaim>;
/** Metadata related to the chain of the Colony */
chainMetadata: ChainMetadata;
/** Colony creation data */
colonyCreateEvent?: Maybe<ColonyCreateEvent>;
/**
* The main member invite object
* It is possible to create multiple member invites for a given colony
Expand All @@ -310,8 +312,6 @@ export type Colony = {
/** ID of the main member invite object */
colonyMemberInviteCode?: Maybe<Scalars['ID']>;
createdAt: Scalars['AWSDateTime'];
/** The block number the colony was created attached */
createdAtBlock?: Maybe<Scalars['Int']>;
domains?: Maybe<ModelDomainConnection>;
expenditures?: Maybe<ModelExpenditureConnection>;
/** Global claim delay for expenditures (in seconds) */
Expand Down Expand Up @@ -835,6 +835,19 @@ export type ColonyContributorRolesArgs = {
sortDirection?: InputMaybe<ModelSortDirection>;
};

export type ColonyCreateEvent = {
__typename?: 'ColonyCreateEvent';
/** The block number the colony was created at */
blockNumber: Scalars['Int'];
/** The address that signed the transaction */
signerAddress: Scalars['String'];
};

export type ColonyCreateEventInput = {
blockNumber: Scalars['Int'];
signerAddress: Scalars['String'];
};

export type ColonyDecision = {
__typename?: 'ColonyDecision';
action?: Maybe<ColonyAction>;
Expand Down Expand Up @@ -1542,8 +1555,8 @@ export type CreateColonyInput = {
balances?: InputMaybe<ColonyBalancesInput>;
chainFundsClaim?: InputMaybe<ColonyChainFundsClaimInput>;
chainMetadata: ChainMetadataInput;
colonyCreateEvent?: InputMaybe<ColonyCreateEventInput>;
colonyMemberInviteCode?: InputMaybe<Scalars['ID']>;
createdAtBlock?: InputMaybe<Scalars['Int']>;
expendituresGlobalClaimDelay?: InputMaybe<Scalars['String']>;
id?: InputMaybe<Scalars['ID']>;
lastUpdatedContributorsWithReputation?: InputMaybe<Scalars['AWSDateTime']>;
Expand Down Expand Up @@ -2983,7 +2996,6 @@ export type ModelColonyActionTypeInput = {
export type ModelColonyConditionInput = {
and?: InputMaybe<Array<InputMaybe<ModelColonyConditionInput>>>;
colonyMemberInviteCode?: InputMaybe<ModelIdInput>;
createdAtBlock?: InputMaybe<ModelIntInput>;
expendituresGlobalClaimDelay?: InputMaybe<ModelStringInput>;
lastUpdatedContributorsWithReputation?: InputMaybe<ModelStringInput>;
name?: InputMaybe<ModelStringInput>;
Expand Down Expand Up @@ -3110,7 +3122,6 @@ export type ModelColonyExtensionFilterInput = {
export type ModelColonyFilterInput = {
and?: InputMaybe<Array<InputMaybe<ModelColonyFilterInput>>>;
colonyMemberInviteCode?: InputMaybe<ModelIdInput>;
createdAtBlock?: InputMaybe<ModelIntInput>;
expendituresGlobalClaimDelay?: InputMaybe<ModelStringInput>;
id?: InputMaybe<ModelIdInput>;
lastUpdatedContributorsWithReputation?: InputMaybe<ModelStringInput>;
Expand Down Expand Up @@ -4369,7 +4380,6 @@ export type ModelSubscriptionColonyExtensionFilterInput = {
export type ModelSubscriptionColonyFilterInput = {
and?: InputMaybe<Array<InputMaybe<ModelSubscriptionColonyFilterInput>>>;
colonyMemberInviteCode?: InputMaybe<ModelSubscriptionIdInput>;
createdAtBlock?: InputMaybe<ModelSubscriptionIntInput>;
expendituresGlobalClaimDelay?: InputMaybe<ModelSubscriptionStringInput>;
id?: InputMaybe<ModelSubscriptionIdInput>;
lastUpdatedContributorsWithReputation?: InputMaybe<ModelSubscriptionStringInput>;
Expand Down Expand Up @@ -9447,8 +9457,8 @@ export type UpdateColonyInput = {
balances?: InputMaybe<ColonyBalancesInput>;
chainFundsClaim?: InputMaybe<ColonyChainFundsClaimInput>;
chainMetadata?: InputMaybe<ChainMetadataInput>;
colonyCreateEvent?: InputMaybe<ColonyCreateEventInput>;
colonyMemberInviteCode?: InputMaybe<Scalars['ID']>;
createdAtBlock?: InputMaybe<Scalars['Int']>;
expendituresGlobalClaimDelay?: InputMaybe<Scalars['String']>;
id: Scalars['ID'];
lastUpdatedContributorsWithReputation?: InputMaybe<Scalars['AWSDateTime']>;
Expand Down

0 comments on commit 9f9904a

Please sign in to comment.