implement refund path for Bob on unexpected stream closure, add contract checks (#56)

This commit is contained in:
noot
2021-12-06 23:18:30 -05:00
committed by GitHub
parent acee21ce19
commit 78752a9088
8 changed files with 302 additions and 151 deletions

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"time"
"github.com/noot/atomic-swap/common"
logging "github.com/ipfs/go-log"
)
@@ -13,7 +15,7 @@ const (
)
var (
log = logging.Logger("common")
log = logging.Logger("monero")
)
// WaitForBlocks waits for a new block to arrive.
@@ -39,3 +41,26 @@ func WaitForBlocks(client Client) error {
return fmt.Errorf("timed out waiting for next block")
}
// CreateMoneroWallet creates a monero wallet from a private keypair.
func CreateMoneroWallet(name string, env common.Environment, client Client, kpAB *PrivateKeyPair) (Address, error) {
t := time.Now().Format("2006-Jan-2-15:04:05")
walletName := fmt.Sprintf("%s-%s", name, t)
if err := client.GenerateFromKeys(kpAB, walletName, "", env); err != nil {
return "", err
}
log.Info("created wallet: ", walletName)
if err := client.Refresh(); err != nil {
return "", err
}
balance, err := client.GetBalance(0)
if err != nil {
return "", err
}
log.Info("wallet balance: ", balance.Balance)
return kpAB.Address(env), nil
}