Skip to content

Commit

Permalink
Cosmetic stuff & move some code around
Browse files Browse the repository at this point in the history
  • Loading branch information
knocte committed Jun 1, 2021
1 parent a23c58e commit 6d8448b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 43 deletions.
24 changes: 2 additions & 22 deletions src/GWallet.Backend/Account.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ open System.IO
open System.Threading.Tasks

open GWallet.Backend.FSharpUtil.UwpHacks
open DotNetLightning.Utils

module Account =

Expand Down Expand Up @@ -74,25 +73,6 @@ module Account =
yield GetAccountFromFile accountFile currency kind
}

let internal GetLightningNodeMasterPrivKey (password: string)
(accountFile: FileRepresentation)
(currency: Currency)
: string =
let utxoAccount =
UtxoCoin.Account.GetAccountFromFile
accountFile
currency
AccountKind.Normal
let utxoAccountPrivateKey =
UtxoCoin.Account.GetPrivateKey (utxoAccount :?> NormalAccount) password
let nodeMasterPrivKey =
UtxoCoin.Lightning.CryptoUtil.AccountPrivateKeyToNodeMasterPrivKey
utxoAccountPrivateKey
let network = UtxoCoin.Account.GetNetwork currency
nodeMasterPrivKey
.RawExtKey()
.ToString network

let GetNormalAccountsPairingInfoForWatchWallet (password: string)
: Option<WatchWalletInfo> =
let allCurrencies = Currency.GetAll()
Expand All @@ -108,11 +88,11 @@ module Account =
AccountKind.Normal

match (utxoCurrencyFile, etherCurrencyFile) with
| (Some (firstUtxoAccountFile, utxoCurrency), Some (firstEtherAccountFile, _etherCurrency)) ->
| Some (firstUtxoAccountFile, utxoCurrency), Some (firstEtherAccountFile, _etherCurrency) ->
let utxoCoinPublicKey = UtxoCoin.Account.GetPublicKeyFromNormalAccountFile firstUtxoAccountFile
let etherPublicAddress = Ether.Account.GetPublicAddressFromNormalAccountFile firstEtherAccountFile
let lightningNodeMasterPrivKey =
GetLightningNodeMasterPrivKey
UtxoCoin.Lightning.Node.GetMasterPrivateKey
password
firstUtxoAccountFile
utxoCurrency
Expand Down
2 changes: 0 additions & 2 deletions src/GWallet.Backend/PublicKey.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,3 @@ type PublicKey private (currencyOpt: Option<Currency>, pubKey: string) =
static member internal Parse (currency: Currency) (pubKey: string): PublicKey =
PublicKey (Some currency, pubKey)

member internal self.ToPubKey() =
PubKey pubKey
4 changes: 2 additions & 2 deletions src/GWallet.Backend/UtxoCoin/Lightning/ChannelManagement.fs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ type ChannelStore(account: IUtxoAccount) =
(password: string)
: ChannelStore =
let channelStore = ChannelStore account
let network = GWallet.Backend.UtxoCoin.Account.GetNetwork (account :> IAccount).Currency
let network = Account.GetNetwork (account :> IAccount).Currency
let nodeMasterPrivKey =
ExtKey.Parse (nodeMasterPrivKeyString, network)
|> NodeMasterPrivKey
Expand All @@ -213,7 +213,7 @@ type ChannelStore(account: IUtxoAccount) =
channelStore

member internal self.GetNodeMasterPrivKey (password: string): string =
let network = GWallet.Backend.UtxoCoin.Account.GetNetwork (self.Account :> IAccount).Currency
let network = Account.GetNetwork (self.Account :> IAccount).Currency
let nodeMasterPrivKey =
match self.Account with
| :? NormalUtxoAccount as normalAccount ->
Expand Down
26 changes: 21 additions & 5 deletions src/GWallet.Backend/UtxoCoin/Lightning/Node.fs
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,19 @@ type IncomingChannelEvent =

type PendingChannel internal (outgoingUnfundedChannel: OutgoingUnfundedChannel) =
member internal self.OutgoingUnfundedChannel = outgoingUnfundedChannel
member self.Currency: Currency =
member __.Currency: Currency =
(outgoingUnfundedChannel.ConnectedChannel.Account :> IAccount).Currency
member self.FundingDestinationString: string =
let network = UtxoCoin.Account.GetNetwork self.Currency
(outgoingUnfundedChannel.FundingDestination.ScriptPubKey.GetDestinationAddress network).ToString()
member self.TransferAmount: TransferAmount = outgoingUnfundedChannel.TransferAmount
member __.TransferAmount: TransferAmount = outgoingUnfundedChannel.TransferAmount

member self.SignTransactionForDestination (account: NormalUtxoAccount)
(txMetadata: TransactionMetadata)
(password: string)
: string =

GWallet.Backend.UtxoCoin.Account.SignTransactionForDestination
Account.SignTransactionForDestination
account
txMetadata
outgoingUnfundedChannel.FundingDestination
Expand Down Expand Up @@ -799,11 +799,27 @@ type Node =
ChainWatcher.CheckForChannelFraudAndSendRevocationTx channelId
self.ChannelStore

static member internal GetMasterPrivateKey (password: string)
(accountFile: FileRepresentation)
(currency: Currency)
: string =
let utxoAccount = Account.GetAccountFromFile accountFile currency AccountKind.Normal
let utxoAccountPrivateKey = Account.GetPrivateKey (utxoAccount :?> NormalAccount) password
let nodeMasterPrivKey =
UtxoCoin.Lightning.CryptoUtil.AccountPrivateKeyToNodeMasterPrivKey
utxoAccountPrivateKey
let network = UtxoCoin.Account.GetNetwork currency
nodeMasterPrivKey
.RawExtKey()
.ToString network


module public Connection =

let public StartClient (channelStore: ChannelStore)
(password: string)
: NodeClient =
let network = GWallet.Backend.UtxoCoin.Account.GetNetwork (channelStore.Account :> IAccount).Currency
let network = Account.GetNetwork (channelStore.Account :> IAccount).Currency
let nodeMasterPrivKey =
ExtKey.Parse(channelStore.GetNodeMasterPrivKey password, network)
|> NodeMasterPrivKey
Expand All @@ -813,7 +829,7 @@ module public Connection =
(password: string)
(bindAddress: IPEndPoint)
: NodeServer =
let network = GWallet.Backend.UtxoCoin.Account.GetNetwork (channelStore.Account :> IAccount).Currency
let network = Account.GetNetwork (channelStore.Account :> IAccount).Currency
let nodeMasterPrivKey =
ExtKey.Parse(channelStore.GetNodeMasterPrivKey password, network)
|> NodeMasterPrivKey
Expand Down
11 changes: 6 additions & 5 deletions src/GWallet.Backend/UtxoCoin/UtxoCoinAccount.fs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ module Account =
let scriptPubKey = Script(scriptPubKeyInBytes)
let coin =
Coin(txHash, uint32 inputOutpointInfo.OutputIndex, Money(inputOutpointInfo.ValueInSatoshis), scriptPubKey)
coin.ToScriptCoin (account.PublicKey.ToPubKey().WitHash.ScriptPubKey) :> ICoin
let pubKey = PubKey (account.PublicKey.ToString ())
coin.ToScriptCoin (pubKey.WitHash.ScriptPubKey) :> ICoin

let private CreateTransactionAndCoinsToBeSigned (account: IUtxoAccount)
(transactionInputs: List<TransactionInputOutpointInfo>)
Expand Down Expand Up @@ -397,10 +398,10 @@ module Account =
raise (InvalidPassword)

let internal SignTransactionForDestination (account: NormalUtxoAccount)
(txMetadata: TransactionMetadata)
(destination: IDestination)
(amount: TransferAmount)
(password: string) =
(txMetadata: TransactionMetadata)
(destination: IDestination)
(amount: TransferAmount)
(password: string) =

let privateKey = GetPrivateKey account password

Expand Down
12 changes: 5 additions & 7 deletions src/GWallet.Frontend.Console/LayerTwo.fs
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,22 @@ module LayerTwo =
metadata
password
| :? UtxoCoin.ReadOnlyUtxoAccount ->
Console.WriteLine("To open a channel from a read-only account the paired wallet must \
sign the funding transaction")
Console.Write("Introduce a file name to save the unsigned transaction: ")
Console.WriteLine "To open a channel from a read-only account the paired wallet must sign the funding transaction."
Console.Write "Introduce a file name to save the unsigned transaction: "
let unsignedFilePath = Console.ReadLine()
let proposal = {
OriginAddress = account.PublicAddress
Amount = pendingChannel.TransferAmount
DestinationAddress = pendingChannel.FundingDestinationString
}
Account.SaveUnsignedTransaction proposal metadata unsignedFilePath
Console.WriteLine("Transaction saved. Now copy it to the device with the private \
key to sign it.")
Console.WriteLine "Transaction saved. Now copy it to the device with the private key to sign it."
let rec getSignedTransaction() =
let signedFilePath =
UserInteraction.AskFileNameToLoad("Enter file name to load the signed transaction: ")
UserInteraction.AskFileNameToLoad "Enter file name to load the signed transaction: "
let signedTransaction = Account.LoadSignedTransactionFromFile signedFilePath.FullName
if signedTransaction.TransactionInfo.Proposal.DestinationAddress <> proposal.DestinationAddress then
Console.WriteLine("Transaction data does not match. Incorrect file?")
Console.WriteLine "Transaction data does not match. Incorrect file?"
getSignedTransaction()
else
signedTransaction.RawTransaction
Expand Down

0 comments on commit 6d8448b

Please sign in to comment.