Skip to content

Commit

Permalink
feat(SPV-1419): suggestion (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-4chain authored Jan 30, 2025
1 parent 708a165 commit 238d67c
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 166 deletions.
73 changes: 73 additions & 0 deletions examples/manage_contacts/helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package main

import (
"fmt"
"log"

"github.com/bitcoin-sv/spv-wallet-go-client/commands"
"github.com/bitcoin-sv/spv-wallet/models"
"github.com/bitcoin-sv/spv-wallet/models/response"
)

type user struct {
xPriv string
xPub string
paymail string
}

type verificationResults struct {
bobValidatedAlicesTotp bool
aliceValidatedBobsTotp bool
}

func examplePaymailCorrectlyEdited(paymail string) string {
if paymail == "" || paymail == "example.com" {
log.Fatal("Invalid configuration - please replace the paymail domain with your own domain")
}
return paymail
}

func assertNoError[T any](val T, err error) T {
if err != nil {
log.Fatalf("unexpected error: %v", err)
}
return val
}

func logSecureMessage(from, to, totp string) {
fmt.Printf("\n!!! SECURE COMMUNICATION REQUIRED !!!\n%s's TOTP code for %s:\n", from, to)
fmt.Printf("TOTP code: %s\n", totp)
fmt.Print("Share using: encrypted message, secure email, phone call or in-person meeting.\n")
}

func mapToContactModel(resp *response.Contact) *models.Contact {
return &models.Contact{
ID: resp.ID,
FullName: resp.FullName,
Paymail: resp.Paymail,
PubKey: resp.PubKey,
Status: resp.Status,
}
}

func setupUsers() {
fmt.Println("0. Setting up users (optional - uncomment if users are not registered)")

// Create account for Alice
assertNoError(clients.admin.CreateXPub(ctx, &commands.CreateUserXpub{
XPub: config.alice.xPub,
}))
assertNoError(clients.admin.CreatePaymail(ctx, &commands.CreatePaymail{
Key: config.alice.xPub,
Address: config.alice.paymail,
}))

// Create account for Bob
assertNoError(clients.admin.CreateXPub(ctx, &commands.CreateUserXpub{
XPub: config.bob.xPub,
}))
assertNoError(clients.admin.CreatePaymail(ctx, &commands.CreatePaymail{
Key: config.bob.xPub,
Address: config.bob.paymail,
}))
}
Loading

0 comments on commit 238d67c

Please sign in to comment.