File tree Expand file tree Collapse file tree 5 files changed +19
-14
lines changed
Expand file tree Collapse file tree 5 files changed +19
-14
lines changed Original file line number Diff line number Diff line change @@ -96,18 +96,14 @@ module Account =
9696 () // TODO: do something in this case??
9797 }
9898
99+ // TODO: add tests for these (just in case address validation breaks after upgrading our dependencies)
99100 let ValidateAddress ( currency : Currency ) ( address : string ) =
100101 match currency with
101102 | Currency.ETH | Currency.ETC ->
102103 Ether.Account.ValidateAddress currency address
103-
104104 | Currency.BTC ->
105105 Bitcoin.Account.ValidateAddress address
106106
107- // FIXME: add bitcoin checksum algorithm?
108- ()
109-
110-
111107 let EstimateFee account amount destination : IBlockchainFeeInfo =
112108 let currency = ( account:> IAccount) .Currency
113109 match currency with
Original file line number Diff line number Diff line change @@ -401,4 +401,9 @@ module internal Account =
401401 if ( address.Length < BITCOIN_ MIN_ ADDRESSES_ LENGTH) then
402402 raise ( AddressWithInvalidLength( BITCOIN_ MIN_ ADDRESSES_ LENGTH))
403403
404- // FIXME: add bitcoin checksum algorithm?
404+ try
405+ BitcoinAddress.Create( address, Config.BitcoinNet) |> ignore
406+ with
407+ // TODO: propose to NBitcoin upstream to generate an NBitcoin exception instead
408+ | :? FormatException ->
409+ raise ( AddressWithInvalidChecksum None)
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ module internal Account =
5454
5555 if ( not ( addressUtil.IsChecksumAddress( address))) then
5656 let validCheckSumAddress = addressUtil.ConvertToChecksumAddress( address)
57- raise ( AddressWithInvalidChecksum( validCheckSumAddress))
57+ raise ( AddressWithInvalidChecksum( Some validCheckSumAddress))
5858
5959 let EstimateFee ( currency : Currency ): MinerFee =
6060 let gasPrice = Ether.Server.GetGasPrice currency
Original file line number Diff line number Diff line change @@ -5,5 +5,5 @@ exception InvalidPassword
55exception DestinationEqualToOrigin
66exception AddressMissingProperPrefix of seq < string >
77exception AddressWithInvalidLength of int
8- exception AddressWithInvalidChecksum of string
8+ exception AddressWithInvalidChecksum of Option < string >
99exception AccountAlreadyAdded
Original file line number Diff line number Diff line change @@ -321,15 +321,19 @@ module UserInteraction =
321321 failwith ( sprintf " Address introduced '%s ' gave a length error with a limit that matches its length: %d =%d "
322322 publicAddress lengthLimitViolated publicAddress.Length)
323323 AskPublicAddress currency askText
324- | AddressWithInvalidChecksum( addressWithValidChecksum ) ->
324+ | AddressWithInvalidChecksum maybeAddressWithValidChecksum ->
325325 Console.Error.WriteLine " WARNING: the address provided didn't pass the checksum, are you sure you copied it properly?"
326- Console.Error.WriteLine " (If you used the clipboard, you're likely copying it from a service that doesn't have checksum validation.)"
327326 Console.Error.WriteLine " (If you copied it by hand or somebody dictated it to you, you probably made a spelling mistake.)"
328- let continueWithoutChecksum = AskYesNo " Continue with this address?"
329- if ( continueWithoutChecksum) then
330- addressWithValidChecksum
331- else
327+ match maybeAddressWithValidChecksum with
328+ | None ->
332329 AskPublicAddress currency askText
330+ | Some addressWithValidChecksum ->
331+ Console.Error.WriteLine " (If you used the clipboard, you're likely copying it from a service that doesn't have checksum validation.)"
332+ let continueWithoutChecksum = AskYesNo " Continue with this address?"
333+ if ( continueWithoutChecksum) then
334+ addressWithValidChecksum
335+ else
336+ AskPublicAddress currency askText
333337 validatedAddress
334338
335339 type private AmountOption =
You can’t perform that action at this time.
0 commit comments