Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcmz committed Sep 26, 2022
1 parent 03fefa2 commit 6380855
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 51 deletions.
60 changes: 29 additions & 31 deletions Sources/Flow/Build/TransactionBuild.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public extension Flow {

/// Reference block id (Optional)
case refBlock(Flow.ID?)

case error
}

Expand Down Expand Up @@ -235,7 +235,7 @@ public extension Flow {
case let .refBlock(value):
refBlock = value
case .error:
break;
break
}
}

Expand Down Expand Up @@ -279,58 +279,57 @@ public extension Flow {
payer: payer ?? proposalKey.address,
authorizers: authorizers)
}

/// Build flow transaction using standard `Flow.Transaction` with async way
/// - parameters:
/// - chainID: The chain id for the transaction, the default value is `flow.chainID`
/// - returns: The type of `EventLoopFuture<Flow.Transaction>`
func buildTransaction(chainID: Flow.ChainID = flow.chainID,
script: String,
agrument: [Flow.Argument] = [],
authorizer: [Flow.Address] = [],
payerAddress: Flow.Address,
proposerKey: Flow.TransactionProposalKey,
limit:BigUInt = BigUInt(9999),
blockID: Flow.ID?
) async throws -> Flow.Transaction {

script: String,
agrument: [Flow.Argument] = [],
authorizer: [Flow.Address] = [],
payerAddress: Flow.Address,
proposerKey: Flow.TransactionProposalKey,
limit: BigUInt = BigUInt(9999),
blockID: Flow.ID?) async throws -> Flow.Transaction
{
return try await buildTransaction(chainID: chainID) {
cadence {
script
}

arguments {
agrument
}

proposer {
proposerKey
}

gasLimit {
limit
}

authorizers {
authorizer
}

payer {
payerAddress
}

refBlock {
blockID?.hex
}
}
}

/// Send signed Transaction to the network
/// - parameters:
/// - chainID: The chain id for the transaction, the default value is `flow.chainID`
/// - signedTransaction: The signed Flow transaction
/// - returns: A future value of transaction id
func sendTransaction(chainID: ChainID = flow.chainID, signedTransaction: Transaction) async throws -> Flow.ID {
func sendTransaction(chainID _: ChainID = flow.chainID, signedTransaction: Transaction) async throws -> Flow.ID {
let api = flow.accessAPI
return try await api.sendTransaction(transaction: signedTransaction)
}
Expand All @@ -351,7 +350,7 @@ public extension Flow {

return try await api.sendTransaction(transaction: signedTx)
}

/// Build, sign and send transaction to the network
/// - parameters:
/// - chainID: The chain id for the transaction, the default value is `flow.chainID`
Expand All @@ -364,35 +363,34 @@ public extension Flow {
authorizer: [Flow.Address] = [],
payerAddress: Flow.Address,
proposerKey: Flow.TransactionProposalKey,
limit:BigUInt = BigUInt(9999),
blockID: Flow.ID?
) async throws -> Flow.ID {

limit: BigUInt = BigUInt(9999),
blockID: Flow.ID?) async throws -> Flow.ID
{
return try await sendTransaction(chainID: chainID, signers: signers) {
cadence {
script
}

arguments {
agrument
}

proposer {
proposerKey
}

gasLimit {
limit
}

authorizers {
authorizer
}

payer {
payerAddress
}

refBlock {
blockID?.hex
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Flow/Cadence/CommonCadence.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,16 @@ public extension Flow {
}
}
}
func isAddressVaildate(address: Flow.Address, network: Flow.ChainID = .mainnet) async -> Bool {

func isAddressVaildate(address: Flow.Address, network _: Flow.ChainID = .mainnet) async -> Bool {
do {
let response = try await flow.accessAPI.getAccountAtLatestBlock(address: address)
return true
} catch {
return false
}
}

func isAddressVaildate(address: String, network: Flow.ChainID = .mainnet) async -> Bool {
return await isAddressVaildate(address: Address(hex: address), network: network)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Flow/Decode/FlowArgument+Decode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// limitations under the License.
//

import Foundation
import BigInt
import Foundation

protocol FlowCodable {
func decode() -> Any?
Expand Down
3 changes: 1 addition & 2 deletions Sources/Flow/Models/FlowAddress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ public extension Flow {
/// The data structure of address in Flow blockchain
/// At the most time, it represents account address
struct Address: FlowEntity, Equatable, Hashable {

static let byteLength = 8

public var data: Data

public init(hex: String) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Flow/Models/FlowTransaction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ public extension Flow {
public init(address: Flow.Address, keyIndex: Int = 0) {
self.address = address
self.keyIndex = keyIndex
self.sequenceNumber = -1
sequenceNumber = -1
}

public init(address: Flow.Address, keyIndex: Int = 0, sequenceNumber: Int64 = -1) {
self.address = address
self.keyIndex = keyIndex
Expand Down
18 changes: 8 additions & 10 deletions Tests/FlowAddressTest.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// File.swift
//
//
//
// Created by Hao Fu on 27/9/2022.
//
Expand All @@ -13,50 +13,48 @@ import CryptoKit
import XCTest

final class FlowAddressTest: XCTestCase {

func testAddressHexType() async throws {
let hex = "0xc7efa8c33fceee03"
let address = Flow.Address(hex: hex)
XCTAssertEqual(address.hex, hex)
XCTAssertEqual(address.bytes.count, 8)
XCTAssertEqual(address.description, hex)

let isVaild = await flow.isAddressVaildate(address: address)
XCTAssertEqual(true, isVaild)
}

func testAddressType() async throws {
let hex = "c7efa8c33fceee03"
let address = Flow.Address(hex: hex)
XCTAssertEqual(address.hex, hex.addHexPrefix())
XCTAssertEqual(address.bytes.count, 8)
XCTAssertEqual(address.description, hex.addHexPrefix())

let isVaild = await flow.isAddressVaildate(address: address)
XCTAssertEqual(true, isVaild)
}

func testInvaildAddressType() async throws {
let hex = "0x03"
let address = Flow.Address(hex: hex)
XCTAssertNotEqual(address.hex, hex)
XCTAssertEqual(address.bytes.count, 8)
XCTAssertNotEqual(address.description, hex)

let isVaild = await flow.isAddressVaildate(address: address)
XCTAssertEqual(false, isVaild)
}

func testInvaildLongAddressType() async throws {
let hex = "0x56519083C3cfeAE833B93a93c843C993bE1D74EA"
let address = Flow.Address(hex: hex)
XCTAssertEqual(address.hex, "0x56519083C3cfeAE8".lowercased())
XCTAssertNotEqual(address.hex, hex)
XCTAssertEqual(address.bytes.count, 8)
XCTAssertNotEqual(address.description, hex)

let isVaild = await flow.isAddressVaildate(address: address)
XCTAssertEqual(false, isVaild)
}

}
2 changes: 1 addition & 1 deletion Tests/NFTCatalogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ final class NFTCatalogTests: XCTestCase {
// XCTAssertEqual(result?.first, 1)
print(result)
}

func testNFTCatalogIDs() async throws {
flow.configure(chainID: .mainnet)
let cadence = """
Expand Down
2 changes: 1 addition & 1 deletion Tests/P256Signer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct ECDSA_P256_Signer: FlowSigner {
self.privateKey = privateKey
}

func sign(transaction: Flow.Transaction, signableData: Data) throws -> Data {
func sign(transaction _: Flow.Transaction, signableData: Data) throws -> Data {
do {
let hashed = SHA256.hash(data: signableData)
return try privateKey.signature(for: hashed).rawRepresentation
Expand Down

0 comments on commit 6380855

Please sign in to comment.