Skip to content

Commit

Permalink
Merge pull request #217 from 0xsequence/feature/listAccountsIntent
Browse files Browse the repository at this point in the history
added ListAccounts intent support
  • Loading branch information
andygruening authored Oct 30, 2024
2 parents 2751e65 + 9f72872 commit 132aa4b
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 2 deletions.
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ void USequenceWallet::ListSessions(const TSuccessCallback<TArray<FSeqListSession
}
}

void USequenceWallet::ListAccounts(const TSuccessCallback<FSeqListAccountsResponse_Data>& OnSuccess, const FFailureCallback& OnFailure) const
{
if (this->SequenceRPCManager)
{
this->SequenceRPCManager->ListAccounts(this->Credentials, OnSuccess, OnFailure);
}
}

void USequenceWallet::GetSessionAuthProof(const FString& Nonce, const TSuccessCallback<FSeqGetSessionAuthProof_Data>& OnSuccess, const FFailureCallback& OnFailure) const
{
if (this->SequenceRPCManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static const FString SendTransactionOP = "sendTransaction";
static const FString FeeOptionsOP = "feeOptions";
static const FString GetIdTokenOP = "getIdToken";
static const FString ListSessionsOP = "listSessions";
static const FString ListAccountsOP = "listAccounts";
static const FString GetSessionAuthProofOP = "sessionAuthProof";
static const FString SignMessageOP = "signMessage";
static const FString FederateSessionOP = "federateAccount";
Expand Down Expand Up @@ -446,6 +447,30 @@ struct SEQUENCEPLUGIN_API FListSessionsData : public FGenericData
}
};

USTRUCT()
struct SEQUENCEPLUGIN_API FListAccountsData : public FGenericData
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
FString wallet = "";

FListAccountsData()
{
Operation = ListAccountsOP;
}

FListAccountsData(const FString& WalletIn)
{
Operation = ListAccountsOP;
wallet = WalletIn;
}

virtual FString GetJson() const override
{
return "";
}
};

USTRUCT()
struct SEQUENCEPLUGIN_API FGetSessionAuthProofData : public FGenericData
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ void USequenceWalletBP::CallOnApiListSessions(const FSequenceResponseStatus& Sta
UE_LOG(LogTemp, Error, TEXT("[Nothing bound to: OnApiListSessions]"));
}

void USequenceWalletBP::CallOnApiListAccounts(const FSequenceResponseStatus& Status, const FSeqListAccountsResponse_Data& Response) const
{
if (this->OnApiListAccounts.IsBound())
this->OnApiListAccounts.Broadcast(Status, Response);
else
UE_LOG(LogTemp, Error, TEXT("[Nothing bound to: OnApiListAccounts]"));
}

void USequenceWalletBP::CallOnApiGetSessionAuthProof(const FSequenceResponseStatus& Status, const FSeqGetSessionAuthProof_Data Response) const
{
if (this->OnApiGetSessionAuthProof.IsBound())
Expand Down Expand Up @@ -455,6 +463,26 @@ void USequenceWalletBP::ApiListSessions()
}
}

void USequenceWalletBP::ApiListAccounts()
{
const TFunction<void(FSeqListAccountsResponse_Data)> OnSuccess = [this](const FSeqListAccountsResponse_Data& Response)
{
this->CallOnApiListAccounts(FSequenceResponseStatus(true, ListAccountsTrt), Response);
};

const TFunction<void(FSequenceError)> OnFailure = [this](const FSequenceError& Err)
{
this->CallOnApiListAccounts(FSequenceResponseStatus(false, Err.Message, ListAccountsTrt), {});
};

const TOptional<USequenceWallet*> WalletOptional = USequenceWallet::Get();
if (WalletOptional.IsSet() && WalletOptional.GetValue())
{
const USequenceWallet* Wallet = WalletOptional.GetValue();
Wallet->ListAccounts(OnSuccess, OnFailure);
}
}

void USequenceWalletBP::ApiGetSessionAuthProof(const FString& Nonce)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ FString USequenceRPCManager::BuildListSessionIntent(const FCredentials_BE& Crede
return Intent;
}

FString USequenceRPCManager::BuildListAccountsIntent(const FCredentials_BE& Credentials) const
{
const FListAccountsData ListAccountsData(Credentials.GetWalletAddress());
const FString Intent = this->GenerateIntent<FListAccountsData>(ListAccountsData);
return Intent;
}

FString USequenceRPCManager::BuildGetSessionAuthProofIntent(const FCredentials_BE& Credentials, const FString& Nonce) const
{
const FGetSessionAuthProofData GetSessionAuthProofData(Credentials.GetNetworkString(), Credentials.GetWalletAddress(), Nonce);
Expand Down Expand Up @@ -441,6 +448,33 @@ void USequenceRPCManager::ListSessions(const FCredentials_BE& Credentials, const
}
}

void USequenceRPCManager::ListAccounts(const FCredentials_BE& Credentials, const TSuccessCallback<FSeqListAccountsResponse_Data>& OnSuccess, const FFailureCallback& OnFailure) const
{
const TSuccessCallback<FString> OnResponse = [OnSuccess, OnFailure](const FString& Response)
{
const FSeqListAccountsResponse ParsedResponse = USequenceSupport::JSONStringToStruct<FSeqListAccountsResponse>(Response);

UE_LOG(LogTemp, Log, TEXT("%s"), *Response);
if (ParsedResponse.IsValid())
{
OnSuccess(ParsedResponse.Response.Data);
}
else
{
OnFailure(FSequenceError(RequestFail, "Error Parsing Response: " + Response));
}
};

if (Credentials.RegisteredValid())
{
this->SequenceRPC(this->BuildAuthenticatorIntentsUrl(), this->BuildListAccountsIntent(Credentials), OnResponse, OnFailure);
}
else
{
OnFailure(FSequenceError(RequestFail, "[Session Not Registered Please Register Session First]"));
}
}

void USequenceRPCManager::GetSessionAuthProof(const FCredentials_BE& Credentials, const FString& Nonce, const TSuccessCallback<FSeqGetSessionAuthProof_Data>& OnSuccess, const FFailureCallback& OnFailure) const
{
const TSuccessCallback<FString> OnResponse = [OnSuccess, OnFailure](const FString& Response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class SEQUENCEPLUGIN_API USequenceRPCManager : public UObject
FString BuildSendTransactionWithFeeIntent(const FCredentials_BE& Credentials, const TArray<TransactionUnion>& Transactions,const FString& FeeQuote) const;
FString BuildGetIdTokenIntent(const FCredentials_BE& Credentials, const FString& nonce) const;
FString BuildListSessionIntent(const FCredentials_BE& Credentials) const;
FString BuildListAccountsIntent(const FCredentials_BE& Credentials) const;
FString BuildGetSessionAuthProofIntent(const FCredentials_BE& Credentials, const FString& Nonce) const;
FString BuildCloseSessionIntent() const;
FString BuildSessionValidationIntent() const;
Expand Down Expand Up @@ -199,6 +200,7 @@ class SEQUENCEPLUGIN_API USequenceRPCManager : public UObject

void ListSessions(const FCredentials_BE& Credentials, const TSuccessCallback<TArray<FSeqListSessions_Session>>& OnSuccess, const FFailureCallback& OnFailure) const;

void ListAccounts(const FCredentials_BE& Credentials, const TSuccessCallback<FSeqListAccountsResponse_Data>& OnSuccess, const FFailureCallback& OnFailure) const;

void GetSessionAuthProof(const FCredentials_BE& Credentials, const FString& Nonce, const TSuccessCallback<FSeqGetSessionAuthProof_Data>& OnSuccess, const FFailureCallback& OnFailure) const;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "CoreMinimal.h"
#include "Marketplace/Marketplace_Enums.h"
#include "Dom/JsonObject.h"
#include "SeqMarketplaceSortBy.generated.h"

USTRUCT(BlueprintType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class SEQUENCEPLUGIN_API USequenceWallet : public UGameInstanceSubsystem

void ListSessions(const TSuccessCallback<TArray<FSeqListSessions_Session>>& OnSuccess, const FFailureCallback& OnFailure) const;

void ListAccounts(const TSuccessCallback<FSeqListAccountsResponse_Data>& OnSuccess, const FFailureCallback& OnFailure) const;

void GetSessionAuthProof(const FString& Nonce, const TSuccessCallback<FSeqGetSessionAuthProof_Data>& OnSuccess, const FFailureCallback& OnFailure) const;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,66 @@ struct SEQUENCEPLUGIN_API FSeqListSessionsResponse
}
};

USTRUCT(Blueprintable)
struct SEQUENCEPLUGIN_API FSeqAccount
{
GENERATED_BODY()

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Default")
FString Id = "";
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Default")
FString Type = "";
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Default")
FString Issuer = "";
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Default")
FString Email = "";


};

USTRUCT(Blueprintable)
struct SEQUENCEPLUGIN_API FSeqListAccountsResponse_Data
{
GENERATED_BODY()

UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
TArray<FSeqAccount> Accounts;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
FString CurrentAccountId = "";
};



USTRUCT()
struct SEQUENCEPLUGIN_API FSeqListAccountsResponse_Response
{
GENERATED_BODY()
UPROPERTY()
FString Code = "";
UPROPERTY()
FSeqListAccountsResponse_Data Data;

bool IsValid() const
{
return Code.Equals(TEXT("accountList"), ESearchCase::IgnoreCase);
}
};

USTRUCT()
struct SEQUENCEPLUGIN_API FSeqListAccountsResponse
{
GENERATED_BODY()

UPROPERTY()
FSeqListAccountsResponse_Response Response;

bool IsValid() const
{
return Response.IsValid();
}
};


//ListSessions//


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnIApiSendTransactionWtihFeeOption
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnIApiSendTransaction, FSequenceResponseStatus, ResponseStatus, FSeqTransactionResponse_Data, Response);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnIApiGetIdToken, FSequenceResponseStatus, ResponseStatus, FSeqIdTokenResponse_Data, Response);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnIApiListSessions, FSequenceResponseStatus, ResponseStatus, const TArray<FSeqListSessions_Session>&, Sessions);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnIApiListAccounts, FSequenceResponseStatus, ResponseStatus, const FSeqListAccountsResponse_Data&, Data);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnIApiGetSessionAuthProof, FSequenceResponseStatus, ResponseStatus, const FSeqGetSessionAuthProof_Data, Response);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnIApiGetSupportedTransakCountries, FSequenceResponseStatus, ResponseStatus, const TArray<FSupportedCountry>&, SupportedCountries);

Expand Down Expand Up @@ -85,6 +86,9 @@ class SEQUENCEPLUGIN_API USequenceWalletBP : public UGameInstanceSubsystem
UPROPERTY(BlueprintAssignable, Category="0xSequence SDK - Events")
FOnIApiListSessions OnApiListSessions;

UPROPERTY(BlueprintAssignable, Category = "0xSequence SDK - Events")
FOnIApiListAccounts OnApiListAccounts;

UPROPERTY(BlueprintAssignable, Category = "0xSequence SDK - Events")
FOnIApiGetSessionAuthProof OnApiGetSessionAuthProof;

Expand Down Expand Up @@ -140,6 +144,7 @@ class SEQUENCEPLUGIN_API USequenceWalletBP : public UGameInstanceSubsystem
void CallOnApiSendTransaction(const FSequenceResponseStatus& Status, const FSeqTransactionResponse_Data& Response) const;
void CallOnApiGetIdToken(const FSequenceResponseStatus& Status, const FSeqIdTokenResponse_Data& Response) const;
void CallOnApiListSessions(const FSequenceResponseStatus& Status, const TArray<FSeqListSessions_Session>& Sessions) const;
void CallOnApiListAccounts(const FSequenceResponseStatus& Status, const FSeqListAccountsResponse_Data& Response) const;
void CallOnApiGetSessionAuthProof(const FSequenceResponseStatus& Status, const FSeqGetSessionAuthProof_Data Response) const;
void CallOnApiGetSupportedTransakCountries(const FSequenceResponseStatus& Status, const TArray<FSupportedCountry>& SupportedCountries) const;

Expand Down Expand Up @@ -265,6 +270,9 @@ class SEQUENCEPLUGIN_API USequenceWalletBP : public UGameInstanceSubsystem
UFUNCTION(BlueprintCallable, Category="0xSequence SDK - Functions")
void ApiListSessions();

UFUNCTION(BlueprintCallable, Category = "0xSequence SDK - Functions")
void ApiListAccounts();

UFUNCTION(BlueprintCallable, Category = "0xSequence SDK - Functions")
void ApiGetSessionAuthProof(const FString& Nonce);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum ETransactionResponseType
SendTransactionTrt UMETA(DisplayName = "SendTransaction"),
GetIdTokenTrt UMETA(DisplayName = "GetIdToken"),
ListSessionsTrt UMETA(DisplayName = "ListSessions"),
ListAccountsTrt UMETA(DisplayName = "ListAccounts"),
GetSessionAuthProofTrt UMETA(DisplayName = "GetSessionAuthProof"),
GetSupportedTransakCountriesTrt UMETA(DisplayName = "GetSupportedTransakCountries"),
PingTrt UMETA(DisplayName = "Ping"),
Expand Down

0 comments on commit 132aa4b

Please sign in to comment.