Files
atomic-swap/crypto/monero/write.go
noot 988b514cf1 cleanup codebase (#72)
* remove unused code, move some funcs around

* move monero/crypto to crypto/monero

* cleanup alice swap_state.go, move funcs

* move rpcclient and types package to common
2022-01-16 23:34:29 -05:00

35 lines
661 B
Go

package mcrypto
import (
"fmt"
"os"
"path/filepath"
"time"
"github.com/noot/atomic-swap/common"
)
// WriteKeysToFile writes the given private key pair to a file within the given path.
func WriteKeysToFile(basepath string, keys *PrivateKeyPair, env common.Environment) error {
t := time.Now().Format("2006-Jan-2-15:04:05")
path := fmt.Sprintf("%s-%s.key", basepath, t)
dir := filepath.Dir(path)
if err := os.MkdirAll(dir, os.ModePerm); err != nil {
return err
}
file, err := os.Create(filepath.Clean(path))
if err != nil {
return err
}
bz, err := keys.Marshal(env)
if err != nil {
return err
}
_, err = file.Write(bz)
return err
}