Skip to content

Commit d333784

Browse files
committed
added rpc calls for GetLinkedWallets and RemoveLinkedWallet, added StringReplace in SequenceSupport.h
1 parent 51f3173 commit d333784

8 files changed

Lines changed: 78 additions & 29 deletions

File tree

Plugins/SequencePlugin/Source/SequencePlugin/Private/Sequence/SequenceAPI.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,35 @@ void USequenceWallet::GetLinkedWallets(const TSuccessCallback<FSeqLinkedWalletsR
511511

512512
void USequenceWallet::RemoveLinkedWallet(const FString& LinkedWalletAddress, const TFunction<void()>& OnSuccess, const FFailureCallback& OnFailure) const
513513
{
514+
const FString& WalletAddress = this->GetWalletAddress();
515+
const FString& MessageToSign = "parent wallet with address " + WalletAddress + LinkedWalletAddress;
516+
517+
const TSuccessCallback<FSeqSignMessageResponse_Response> OnSignatureSuccess = [this, LinkedWalletAddress, WalletAddress, MessageToSign, OnSuccess, OnFailure](FSeqSignMessageResponse_Response SignatureResponse)
518+
{
519+
if (this->SequenceRPCManager)
520+
{
521+
const FString& ChainId = this->Credentials.GetNetworkString();
522+
FSeqLinkedWalletRequest Request;
523+
Request.SignatureChainId = ChainId;
524+
Request.ParentWalletAddress = WalletAddress;
525+
Request.ParentWalletMessage = MessageToSign;
526+
Request.ParentWalletSignature = SignatureResponse.Data.Signature;
527+
Request.LinkedWalletAddress = LinkedWalletAddress;
528+
529+
this->SequenceRPCManager->RemoveLinkedWallet(Request, OnSuccess, OnFailure);
530+
}
531+
else
532+
{
533+
OnFailure(FSequenceError(RequestFail, "SequenceRPCManager is not available."));
534+
}
535+
};
536+
537+
const TFunction<void (FString, FSequenceError)> OnSignatureFailure = [OnFailure](FString Data, FSequenceError Err)
538+
{
539+
OnFailure(FSequenceError(RequestFail, "Error Parsing Response: " + Err.Message));
540+
};
514541

542+
this->SignMessage(MessageToSign, OnSignatureSuccess, OnFailure);
515543
}
516544

517545
//Indexer Calls

Plugins/SequencePlugin/Source/SequencePlugin/Private/Sequence/SequenceWalletBP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ void USequenceWalletBP::ApiSignOut()
304304
}
305305
}
306306

307-
void USequenceWalletBP::GetLinkedWallets(FOnLinkedWallets OnSuccess, FOnFailure OnFailure)
307+
void USequenceWalletBP::GetLinkedWallets(FOnLinkedWallets OnSuccess, FOnLinkedWalletsFailure OnFailure)
308308
{
309309
const TFunction<void (FSeqLinkedWalletsResponse)> OnApiSuccess = [OnSuccess](const FSeqLinkedWalletsResponse& LinkedWallets)
310310
{
@@ -324,7 +324,7 @@ void USequenceWalletBP::GetLinkedWallets(FOnLinkedWallets OnSuccess, FOnFailure
324324
}
325325
}
326326

327-
void USequenceWalletBP::RemoveLinkedWallet(const FString& LinkedWalletAddress, FOnSuccess OnSuccess, FOnFailure OnFailure)
327+
void USequenceWalletBP::RemoveLinkedWallet(const FString& LinkedWalletAddress, FOnSuccess OnSuccess, FOnLinkedWalletsFailure OnFailure)
328328
{
329329
const TFunction<void()> OnApiSuccess = [OnSuccess]()
330330
{

Plugins/SequencePlugin/Source/SequencePlugin/Private/SequenceRPCManager.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "Sequence/SequenceAPI.h"
1414
#include "Sequence/SequenceAuthResponseIntent.h"
1515
#include "Misc/DateTime.h"
16+
#include "Util/Log.h"
1617

1718
template<typename T> FString USequenceRPCManager::GenerateIntent(T Data, TOptional<int64> CurrentTime) const
1819
{
@@ -41,6 +42,8 @@ void USequenceRPCManager::SequenceRPC(const FString& Url, const FString& Content
4142
{
4243
UResponseSignatureValidator& RPCValidator = *Validator;
4344

45+
SEQ_LOG_EDITOR(Display, TEXT("%s - %s"), *Url, *Content);
46+
4447
NewObject<URequestHandler>()
4548
->PrepareRequest()
4649
->WithUrl(Url)
@@ -55,6 +58,8 @@ void USequenceRPCManager::SequenceRPC(const FString& Url, const FString& Content
5558

5659
void USequenceRPCManager::SequenceRPC(const FString& Url, const FString& Content, const TSuccessCallback<FHttpResponsePtr>& OnSuccess, const FFailureCallback& OnFailure) const
5760
{
61+
SEQ_LOG_EDITOR(Display, TEXT("%s - %s"), *Url, *Content);
62+
5863
NewObject<URequestHandler>()
5964
->PrepareRequest()
6065
->WithUrl(Url)
@@ -71,10 +76,8 @@ void USequenceRPCManager::SendIntent(const FString& Url, TFunction<FString(TOpti
7176
{
7277
this->SequenceRPC(Url, ContentGenerator(TOptional<int64>()), [this, Url, ContentGenerator, OnSuccess, OnFailure](FHttpResponsePtr Response)
7378
{
74-
UE_LOG(LogTemp, Display, TEXT("SUCCESS"));
75-
UE_LOG(LogTemp, Display, TEXT("CONTENT"));
7679
FString Content = UTF8ToString(FUnsizedData(Response.Get()->GetContent()));
77-
UE_LOG(LogTemp, Display, TEXT("%s"), *Content);
80+
SEQ_LOG_EDITOR(Display, TEXT("%s"), *Content);
7881

7982
if(Content.Contains("intent is invalid: intent expired") || Content.Contains("intent is invalid: intent issued in the future"))
8083
{
@@ -952,20 +955,31 @@ void USequenceRPCManager::ForceOpenSessionInUse(const TSuccessCallback<FCredenti
952955
}, OnOpenResponse, OnFailure);
953956
}
954957

955-
void USequenceRPCManager::GetLinkedWallets(const FSeqLinkedWalletRequest& Request, const TSuccessCallback<FSeqLinkedWalletsResponse>& OnSuccess, const FFailureCallback& OnFailure)
958+
void USequenceRPCManager::GetLinkedWallets(const FSeqLinkedWalletRequest& Request, const TSuccessCallback<FSeqLinkedWalletsResponse>& OnSuccess, const FFailureCallback& OnFailure) const
956959
{
957-
/*this->SendIntent(this->BuildAPIUrl("GetLinkedWallets"),[this, ChainId, WalletAddress, Message, Signature](const TOptional<int64>& CurrentTime)
960+
const TSuccessCallback<FString> OnResponse = [this, OnSuccess](const FString& OnResponse)
958961
{
959-
return BuildValidateMessageSignatureIntent(ChainId, WalletAddress, Message, Signature, CurrentTime);
960-
}, OnResponse, OnFailure);*/
962+
const FSeqLinkedWalletsResponse LinkedWallets = USequenceSupport::JSONStringToStruct<FSeqLinkedWalletsResponse>(OnResponse);
963+
OnSuccess(LinkedWallets);
964+
};
965+
966+
this->SendIntent(this->BuildAPIUrl("GetLinkedWallets"),[this, Request](const TOptional<int64>& CurrentTime)
967+
{
968+
return USequenceSupport::StructToString(Request);
969+
}, OnResponse, OnFailure);
961970
}
962971

963-
void USequenceRPCManager::RemoveLinkedWallet(const FSeqLinkedWalletRequest& Request, const TFunction<void()>& OnSuccess, const FFailureCallback& OnFailure)
972+
void USequenceRPCManager::RemoveLinkedWallet(const FSeqLinkedWalletRequest& Request, const TFunction<void()>& OnSuccess, const FFailureCallback& OnFailure) const
964973
{
965-
/*this->SendIntent(this->BuildAPIUrl("RemoveLinkedWallet"),[this, ChainId, WalletAddress, Message, Signature](const TOptional<int64>& CurrentTime)
974+
const TSuccessCallback<FString> OnResponse = [this, OnSuccess](const FString& OnResponse)
966975
{
967-
return BuildValidateMessageSignatureIntent(ChainId, WalletAddress, Message, Signature, CurrentTime);
968-
}, OnResponse, OnFailure);*/
976+
OnSuccess();
977+
};
978+
979+
this->SendIntent(this->BuildAPIUrl("RemoveLinkedWallet"),[this, Request](const TOptional<int64>& CurrentTime)
980+
{
981+
return USequenceSupport::StructToString(Request);
982+
}, OnResponse, OnFailure);
969983
}
970984

971985
void USequenceRPCManager::FederateEmailSession(const FString& WalletIn, const FString& CodeIn, const TFunction<void()>& OnSuccess, const FFailureCallback& OnFailure)

Plugins/SequencePlugin/Source/SequencePlugin/Private/SequenceRPCManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,14 @@ class SEQUENCEPLUGIN_API USequenceRPCManager : public UObject
282282
* @param OnSuccess
283283
* @param OnFailure
284284
*/
285-
void GetLinkedWallets(const FSeqLinkedWalletRequest& Request, const TSuccessCallback<FSeqLinkedWalletsResponse>& OnSuccess, const FFailureCallback& OnFailure);
285+
void GetLinkedWallets(const FSeqLinkedWalletRequest& Request, const TSuccessCallback<FSeqLinkedWalletsResponse>& OnSuccess, const FFailureCallback& OnFailure) const;
286286

287287
/**
288288
* GetLinkedWallets
289289
* @param OnSuccess
290290
* @param OnFailure
291291
*/
292-
void RemoveLinkedWallet(const FSeqLinkedWalletRequest& Request, const TFunction<void()>& OnSuccess, const FFailureCallback& OnFailure);
292+
void RemoveLinkedWallet(const FSeqLinkedWalletRequest& Request, const TFunction<void()>& OnSuccess, const FFailureCallback& OnFailure) const;
293293

294294
//Auth Calls//
295295

Plugins/SequencePlugin/Source/SequencePlugin/Private/Util/SequenceSupport.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,11 @@ FString USequenceSupport::StringCleanup(FString String)
575575
return (*Ret);
576576
}
577577

578+
void USequenceSupport::StringReplace(FString* Input, const FString& Search, const FString& Replacement)
579+
{
580+
Input->ReplaceInline(*Search, *Replacement, ESearchCase::IgnoreCase);
581+
}
582+
578583
int64 USequenceSupport::StringDateToUnixDate(const FString& Iso8601)
579584
{
580585
FDateTime ParsedDate;

Plugins/SequencePlugin/Source/SequencePlugin/Public/Sequence/SequenceResponseIntent.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -545,19 +545,19 @@ struct SEQUENCEPLUGIN_API FSeqLinkedWalletRequest
545545
{
546546
GENERATED_BODY()
547547

548-
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
548+
UPROPERTY(BlueprintReadWrite, meta = (JsonFieldName = "signatureChainId"))
549549
FString SignatureChainId = "";
550550

551-
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
551+
UPROPERTY(BlueprintReadWrite, meta = (JsonFieldName = "parentWalletAddress"))
552552
FString ParentWalletAddress = "";
553553

554-
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
554+
UPROPERTY(BlueprintReadWrite, meta = (JsonFieldName = "parentWalletMessage"))
555555
FString ParentWalletMessage = "";
556556

557-
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
557+
UPROPERTY(BlueprintReadWrite, meta = (JsonFieldName = "parentWalletSignature"))
558558
FString ParentWalletSignature = "";
559559

560-
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
560+
UPROPERTY(BlueprintReadWrite, meta = (JsonFieldName = "linkedWalletAddress"))
561561
FString LinkedWalletAddress = "";
562562
};
563563

@@ -566,19 +566,19 @@ struct SEQUENCEPLUGIN_API FSeqLinkedWallet
566566
{
567567
GENERATED_BODY()
568568

569-
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
569+
UPROPERTY(BlueprintReadWrite, meta = (JsonFieldName = "id"))
570570
int64 Id = 0;
571571

572-
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
572+
UPROPERTY(BlueprintReadWrite, meta = (JsonFieldName = "walletType"))
573573
FString WalletType = "";
574574

575-
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
575+
UPROPERTY(BlueprintReadWrite, meta = (JsonFieldName = "walletAddress"))
576576
FString WalletAddress = "";
577577

578-
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
578+
UPROPERTY(BlueprintReadWrite, meta = (JsonFieldName = "linkedWalletAddress"))
579579
FString LinkedWalletAddress = "";
580580

581-
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
581+
UPROPERTY(BlueprintReadWrite, meta = (JsonFieldName = "createdAt"))
582582
FString CreatedAt = "";
583583
};
584584

@@ -587,7 +587,7 @@ struct SEQUENCEPLUGIN_API FSeqLinkedWalletsResponse
587587
{
588588
GENERATED_BODY()
589589

590-
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Default")
590+
UPROPERTY(BlueprintReadWrite, meta = (JsonFieldName = "linkedWallets"))
591591
TArray<FSeqLinkedWallet> LinkedWallets;
592592
};
593593

Plugins/SequencePlugin/Source/SequencePlugin/Public/Sequence/SequenceWalletBP.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnIApiListAccounts, FSequenceRespo
2727
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnIApiGetSessionAuthProof, FSequenceResponseStatus, ResponseStatus, const FSeqGetSessionAuthProof_Data, Response);
2828
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnIApiGetSupportedTransakCountries, FSequenceResponseStatus, ResponseStatus, const TArray<FSupportedCountry>&, SupportedCountries);
2929
DECLARE_DYNAMIC_DELEGATE_OneParam(FOnLinkedWallets, const FSeqLinkedWalletsResponse&, LinkedWallets);
30-
DECLARE_DYNAMIC_DELEGATE_OneParam(FOnFailure, const FString&, Error);
30+
DECLARE_DYNAMIC_DELEGATE_OneParam(FOnLinkedWalletsFailure, const FString&, Error);
3131
DECLARE_DYNAMIC_DELEGATE(FOnSuccess);
3232

3333
//Api//
@@ -245,10 +245,10 @@ class SEQUENCEPLUGIN_API USequenceWalletBP : public UGameInstanceSubsystem
245245
void ApiSignOut();
246246

247247
UFUNCTION(BlueprintCallable, Category="0xSequence SDK - Functions")
248-
void GetLinkedWallets(FOnLinkedWallets OnSuccess, FOnFailure OnFailure);
248+
void GetLinkedWallets(FOnLinkedWallets OnSuccess, FOnLinkedWalletsFailure OnFailure);
249249

250250
UFUNCTION(BlueprintCallable, Category="0xSequence SDK - Functions")
251-
void RemoveLinkedWallet(const FString& LinkedWalletAddress, FOnSuccess OnSuccess, FOnFailure OnFailure);
251+
void RemoveLinkedWallet(const FString& LinkedWalletAddress, FOnSuccess OnSuccess, FOnLinkedWalletsFailure OnFailure);
252252

253253
//SequenceApi//
254254

Plugins/SequencePlugin/Source/SequencePlugin/Public/Util/SequenceSupport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ class SEQUENCEPLUGIN_API USequenceSupport : public UObject
399399
{
400400
FString Ret;
401401
FJsonObjectConverter::UStructToJsonObjectString<T>(StructVar, Ret, 0, 0);
402+
StringReplace(&Ret, "\n", "");
402403
return Ret;
403404
}
404405

@@ -511,4 +512,5 @@ class SEQUENCEPLUGIN_API USequenceSupport : public UObject
511512
* some special edge cases from json responses / parsing as well!
512513
*/
513514
static FString StringCleanup(FString String);
515+
static void StringReplace(FString* Input, const FString& Search, const FString& Replacement);
514516
};

0 commit comments

Comments
 (0)