Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix send to self error for zcash #5278

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ZcashAdapter {
network = ZcashNetworkBuilder.network(for: .mainnet)

// todo: update fee settings
fee = 10_000//network.constants.defaultFee().decimalValue.decimalValue
fee = Zatoshi(10_000).decimalValue.decimalValue//network.constants.defaultFee().decimalValue.decimalValue

token = wallet.token
transactionSource = wallet.transactionSource
Expand Down Expand Up @@ -515,7 +515,7 @@ extension ZcashAdapter {
outputParamsURL: outputParamsURL(uniqueId: uniqueId),
saplingParamsSourceURL: SaplingParamsSourceURL.default,
alias: .custom(uniqueId),
loggingPolicy: .default(.debug)
loggingPolicy: .default(.error)
)
}

Expand Down Expand Up @@ -714,9 +714,9 @@ extension ZcashAdapter: ISendZcashAdapter {
max(0, balanceData.available - fee)
}

func validate(address: String) throws -> AddressType {
guard address != receiveAddress.address else {
throw AppError.addressInvalid
func validate(address: String, checkSendToSelf: Bool = true) throws -> AddressType {
if checkSendToSelf, address == receiveAddress.address {
throw AppError.zcash(reason: .sendToSelf)
}

do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class ZcashAddressParserItem {
self.parserType = parserType
}

private func validate(address: String) -> Single<Address> {
private func validate(address: String, checkSendToSelf: Bool) -> Single<Address> {
do {
switch parserType {
case .adapter(let adapter):
_ = try adapter.validate(address: address)
_ = try adapter.validate(address: address, checkSendToSelf: checkSendToSelf)
return Single.just(Address(raw: address, domain: nil))
case .validator(let validator):
try validator.validate(address: address)
Expand All @@ -29,13 +29,12 @@ class ZcashAddressParserItem {
extension ZcashAddressParserItem: IAddressParserItem {

func handle(address: String) -> Single<Address> {
validate(address: address)
validate(address: address, checkSendToSelf: true)
}

func isValid(address: String) -> Single<Bool> {
validate(address: address)
validate(address: address, checkSendToSelf: false)
.map { _ in true }
.catchErrorJustReturn(false)
}

}
Expand Down
2 changes: 1 addition & 1 deletion UnstoppableWallet/UnstoppableWallet/Core/Protocols.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protocol ISendBinanceAdapter {

protocol ISendZcashAdapter {
var availableBalance: Decimal { get }
func validate(address: String) throws -> ZcashAdapter.AddressType
func validate(address: String, checkSendToSelf: Bool) throws -> ZcashAdapter.AddressType
var fee: Decimal { get }
func sendSingle(amount: Decimal, address: Recipient, memo: Memo?) -> Single<Void>
func recipient(from stringEncodedAddress: String) -> Recipient?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SendZcashService {

private func syncState() {
let address = addressService.state.address?.raw
let addressType = address.map { try? adapter.validate(address: $0) }
let addressType = address.map { try? adapter.validate(address: $0, checkSendToSelf: true) }
isMemoAvailable = addressType.map { $0 == .shielded } ?? false

guard amountCautionService.amountCaution == nil,
Expand Down