Skip to content

Commit

Permalink
Merge pull request #187 from barrasso/patch-6
Browse files Browse the repository at this point in the history
Update ETHRegistrarController.swift
  • Loading branch information
TonioMacaronio authored May 6, 2019
2 parents 041053d + 0ac5243 commit 282f919
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Sources/web3swift/Utils/ENS/ETHRegistrarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import Foundation
import BigInt
//import EthereumAddress

public extension ENS {
class ETHRegistrarController {
Expand Down Expand Up @@ -51,26 +50,26 @@ public extension ENS {
return available
}

public func calculateCommitmentHash(name: String, owner: EthereumAddress, secret: [UInt32]) throws -> [UInt32] {
guard let transaction = self.contract.read("makeCommitment", parameters: [name, owner, secret] as [AnyObject], extraData: Data(), transactionOptions: defaultOptions) else {throw Web3Error.transactionSerializationError}
public func calculateCommitmentHash(name: String, owner: EthereumAddress, secret: String) throws -> Data {
guard let transaction = self.contract.read("makeCommitment", parameters: [name, owner.address, secret] as [AnyObject], extraData: Data(), transactionOptions: defaultOptions) else {throw Web3Error.transactionSerializationError}
guard let result = try? transaction.call(transactionOptions: defaultOptions) else {throw Web3Error.processingError(desc: "Can't call transaction")}
guard let hash = result["0"] as? [UInt32] else {throw Web3Error.processingError(desc: "Can't get answer")}
guard let hash = result["0"] as? Data else {throw Web3Error.processingError(desc: "Can't get answer")}
return hash
}

public func sumbitCommitment(from: EthereumAddress, commitment: [UInt32]) throws -> WriteTransaction {
public func sumbitCommitment(from: EthereumAddress, commitment: Data) throws -> WriteTransaction {
defaultOptions.from = from
defaultOptions.to = self.address
guard let transaction = self.contract.write("commit", parameters: [commitment as AnyObject], extraData: Data(), transactionOptions: defaultOptions) else {throw Web3Error.transactionSerializationError}
return transaction
}

public func registerName(from: EthereumAddress, name: String, owner: EthereumAddress, duration: UInt32, secret: [UInt32], price: String) throws -> WriteTransaction {
public func registerName(from: EthereumAddress, name: String, owner: EthereumAddress, duration: UInt, secret: String, price: String) throws -> WriteTransaction {
guard let amount = Web3.Utils.parseToBigUInt(price, units: .eth) else {throw Web3Error.inputError(desc: "Wrong price: no way for parsing to ether units")}
defaultOptions.value = amount
defaultOptions.from = from
defaultOptions.to = self.address
guard let transaction = self.contract.write("register", parameters: [name, owner, duration, secret] as [AnyObject], extraData: Data(), transactionOptions: defaultOptions) else {throw Web3Error.transactionSerializationError}
guard let transaction = self.contract.write("register", parameters: [name, owner.address, duration, secret] as [AnyObject], extraData: Data(), transactionOptions: defaultOptions) else {throw Web3Error.transactionSerializationError}
return transaction
}

Expand Down

0 comments on commit 282f919

Please sign in to comment.