Skip to content

Commit

Permalink
Add mutation for syncing existing creator contracts (#1188)
Browse files Browse the repository at this point in the history
* Add admin query

* Graphql lint

* Use chainAddress instead
  • Loading branch information
jarrel-b authored Sep 19, 2023
1 parent 49032d2 commit a7172a2
Show file tree
Hide file tree
Showing 6 changed files with 575 additions and 219 deletions.
444 changes: 359 additions & 85 deletions graphql/generated/generated.go

Large diffs are not rendered by default.

283 changes: 149 additions & 134 deletions graphql/model/models_gen.go

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions graphql/model/remapgen_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions graphql/resolver/schema.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions graphql/schema/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2173,6 +2173,17 @@ union SyncCreatedTokensForUsernamePayloadOrError =
| ErrNotAuthorized
| ErrSyncFailed

type SyncCreatedTokensForUsernameAndExistingContractPayload {
message: String!
}

union SyncCreatedTokensForUsernameAndExistingContractPayloadOrError =
SyncCreatedTokensForUsernameAndExistingContractPayload
| ErrInvalidInput
| ErrNotAuthorized
| ErrSyncFailed
| ErrCommunityNotFound

type BanUserFromFeedPayload {
user: GalleryUser
}
Expand Down Expand Up @@ -2674,6 +2685,10 @@ type Mutation {
username: String!
chains: [Chain!]!
): SyncCreatedTokensForUsernamePayloadOrError @retoolAuth
syncCreatedTokensForUsernameAndExistingContract(
username: String!
chainAddress: ChainAddressInput!
): SyncCreatedTokensForUsernameAndExistingContractPayloadOrError @retoolAuth
banUserFromFeed(username: String!, action: String!): BanUserFromFeedPayloadOrError @retoolAuth
unbanUserFromFeed(username: String!): UnbanUserFromFeedPayloadOrError @retoolAuth
mintPremiumCardToWallet(
Expand Down
25 changes: 25 additions & 0 deletions publicapi/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,31 @@ func (api TokenAPI) SyncCreatedTokensForExistingContract(ctx context.Context, co
return api.multichainProvider.SyncCreatedTokensForExistingContract(ctx, userID, contractID)
}

func (api TokenAPI) SyncCreatedTokensForExistingContractAdmin(ctx context.Context, userID persist.DBID, chainAddress persist.ChainAddress) error {
// Validate
if err := validate.ValidateFields(api.validator, validate.ValidationMap{
"userID": validate.WithTag(userID, "required"),
"chain": validate.WithTag(chainAddress.Chain(), "chain"),
"address": validate.WithTag(chainAddress.Address(), "required"),
}); err != nil {
return err
}

contract, err := api.repos.ContractRepository.GetByAddress(ctx, chainAddress.Address(), chainAddress.Chain())
if err != nil {
return err
}

key := fmt.Sprintf("sync:created:contract:%s:%s", userID.String(), contract.ID)

if err := api.throttler.Lock(ctx, key); err != nil {
return ErrTokenRefreshFailed{Message: err.Error()}
}
defer api.throttler.Unlock(ctx, key)

return api.multichainProvider.SyncCreatedTokensForExistingContract(ctx, userID, contract.ID)
}

func (api TokenAPI) RefreshToken(ctx context.Context, tokenDBID persist.DBID) error {
if err := validate.ValidateFields(api.validator, validate.ValidationMap{
"tokenID": validate.WithTag(tokenDBID, "required"),
Expand Down

0 comments on commit a7172a2

Please sign in to comment.