Exemplo n.º 1
0
        NewWallet(string filename, string password,
                  PrivateKey privateViewKey, string address)
        {
            if (!KeyOps.IsValidKey(privateViewKey))
            {
                return(Either.Left <Error, WalletBackend>(
                           Error.InvalidPrivateKey()
                           ));
            }

            if (File.Exists(filename))
            {
                return(Either.Left <Error, WalletBackend>(
                           Error.FileAlreadyExists()
                           ));
            }

            /* If we can get the keys from the address, make a new view wallet,
             * save it, and return it. Else, return the error */
            return(Addresses.KeysFromAddress(address).Fmap(
                       publicKeys => {
                WalletBackend wallet = new WalletBackend(
                    filename, password, privateViewKey, publicKeys
                    );

                wallet.Save();

                return Either.Right <Error, WalletBackend>(wallet);
            }
                       ));
        }
Exemplo n.º 2
0
        NewWallet(string filename, string password,
                  PrivateKeys privateKeys)
        {
            if (!KeyOps.IsValidKey(privateKeys.spendKey) ||
                !KeyOps.IsValidKey(privateKeys.viewKey))
            {
                return(Either.Left <Error, WalletBackend>(
                           Error.InvalidPrivateKey()
                           ));
            }

            if (File.Exists(filename))
            {
                return(Either.Left <Error, WalletBackend>(
                           Error.FileAlreadyExists()
                           ));
            }

            /* Create the wallet instance */
            WalletBackend wallet = new WalletBackend(
                filename, password, privateKeys
                );

            /* Save it */
            wallet.Save();

            /* Return it */
            return(Either.Right <Error, WalletBackend>(wallet));
        }