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

Ci/test and lint updated #26

Merged
merged 2 commits into from
Apr 25, 2022
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
38 changes: 38 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
24 changes: 24 additions & 0 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Swift

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: macos-12

steps:
- uses: actions/checkout@v2
- name: Build
run: swift build
- name: Run tests
run: swift test --enable-code-coverage
- name: Test coverage
uses: maxep/spm-lcov-action@0.3.0
with:
output-file: ./coverage/lcov.info

18 changes: 18 additions & 0 deletions .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: SwiftLint

on:
pull_request:
paths:
- '.github/workflows/swiftlint.yml'
- '.swiftlint.yml'
- '**/*.swift'

jobs:
SwiftLint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: GitHub Action for SwiftLint
uses: norio-nomura/action-swiftlint@3.2.1
with:
args: --config ".swiftlint.yml"
27 changes: 27 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
opt_in_rules:
- empty_count
included:
- Sources
disabled_rules:
- function_parameter_count
- identifier_name
- type_body_length
- file_length
- empty_count
- type_name
- shorthand_operator

force_cast: warning
force_try:
severity: warning
line_length: 140
function_body_length: 200

type_name:
min_length: 2 # only warning
max_length: # warning and error
warning: 40
error: 50
excluded: iPhone # excluded via string
allowed_symbols: ["_"] # these are allowed in type names
reporter: "xcode"
10 changes: 5 additions & 5 deletions Sources/Metaplex/Drivers/Identity/GuestIdentityDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import Solana
class GuestIdentityDriver: IdentityDriver {
private let solanaRPC: Api
internal let publicKey: PublicKey
init(solanaRPC: Api){
init(solanaRPC: Api) {
self.solanaRPC = solanaRPC
self.publicKey = PublicKey.default
}
func sendTransaction(serializedTransaction: String, onComplete: @escaping(Result<TransactionID, IdentityDriverError>) -> Void){

func sendTransaction(serializedTransaction: String, onComplete: @escaping(Result<TransactionID, IdentityDriverError>) -> Void) {
self.solanaRPC.sendTransaction(serializedTransaction: serializedTransaction) { result in
switch result {
case .success(let transactionID):
Expand All @@ -26,11 +26,11 @@ class GuestIdentityDriver: IdentityDriver {
}
}
}

func signTransaction(transaction: Transaction, onComplete: @escaping (Result<Transaction, IdentityDriverError>) -> Void) {
onComplete(.failure(IdentityDriverError.methodNotAvailable))
}

func signAllTransactions(transactions: [Transaction], onComplete: @escaping (Result<[Transaction?], IdentityDriverError>) -> Void) {
onComplete(.failure(IdentityDriverError.methodNotAvailable))
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/Metaplex/Drivers/Identity/KeypairIdentityDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import Foundation
import Solana

class KeypairIdentityDriver: IdentityDriver {

internal var publicKey: PublicKey
private let secretKey: Data
private let account: Account
private let solanaRPC: Api
init(solanaRPC: Api, account: Account){
init(solanaRPC: Api, account: Account) {
self.solanaRPC = solanaRPC
self.publicKey = account.publicKey
self.secretKey = account.secretKey
self.account = account
}
func sendTransaction(serializedTransaction: String, onComplete: @escaping(Result<TransactionID, IdentityDriverError>) -> Void){

func sendTransaction(serializedTransaction: String, onComplete: @escaping(Result<TransactionID, IdentityDriverError>) -> Void) {
self.solanaRPC.sendTransaction(serializedTransaction: serializedTransaction) { result in
switch result {
case .success(let transactionID):
Expand All @@ -31,18 +31,18 @@ class KeypairIdentityDriver: IdentityDriver {
}
}
}

func signTransaction(transaction: Transaction, onComplete: @escaping (Result<Transaction, IdentityDriverError>) -> Void) {
var transaction = transaction
transaction.sign(signers: [account])
.onSuccess{ onComplete(.success(transaction))}
.onSuccess { onComplete(.success(transaction))}
}

func signAllTransactions(transactions: [Transaction], onComplete: @escaping (Result<[Transaction?], IdentityDriverError>) -> Void) {
var mutableTransactions: [Transaction?] = []
transactions.forEach { transaction in
var mutableTransaction = transaction
mutableTransaction.sign(signers:[account]).onSuccess { _ in
mutableTransaction.sign(signers: [account]).onSuccess { _ in
mutableTransactions.append(mutableTransaction)
}.onFailure { _ in
mutableTransactions.append(nil)
Expand Down
10 changes: 5 additions & 5 deletions Sources/Metaplex/Drivers/Identity/ReadOnlyIdentityDriver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import Solana
class ReadOnlyIdentityDriver: IdentityDriver {
let publicKey: PublicKey
private let solanaRPC: Api
init(solanaRPC: Api, publicKey: PublicKey){
init(solanaRPC: Api, publicKey: PublicKey) {
self.solanaRPC = solanaRPC
self.publicKey = publicKey
}
func sendTransaction(serializedTransaction: String, onComplete: @escaping(Result<TransactionID, IdentityDriverError>) -> Void){

func sendTransaction(serializedTransaction: String, onComplete: @escaping(Result<TransactionID, IdentityDriverError>) -> Void) {
self.solanaRPC.sendTransaction(serializedTransaction: serializedTransaction) { result in
switch result {
case .success(let transactionID):
Expand All @@ -26,11 +26,11 @@ class ReadOnlyIdentityDriver: IdentityDriver {
}
}
}

func signTransaction(transaction: Transaction, onComplete: @escaping (Result<Transaction, IdentityDriverError>) -> Void) {
onComplete(.failure(IdentityDriverError.methodNotAvailable))
}

func signAllTransactions(transactions: [Transaction], onComplete: @escaping (Result<[Transaction?], IdentityDriverError>) -> Void) {
onComplete(.failure(IdentityDriverError.methodNotAvailable))
}
Expand Down
36 changes: 18 additions & 18 deletions Sources/Metaplex/Metaplex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,46 @@ public class Metaplex {
let connection: Connection
private var identityDriver: IdentityDriver
private var storageDriver: StorageDriver

lazy var nft: NftClient = NftClient(metaplex: self)

public init(connection: Connection, identityDriver: IdentityDriver, storageDriver: StorageDriver) {
self.connection = connection
self.identityDriver = identityDriver
self.storageDriver = storageDriver
}

public func identity() -> IdentityDriver {
return self.identityDriver
}
public func setIdentity(identityDriver: IdentityDriver) -> IdentityDriver{

public func setIdentity(identityDriver: IdentityDriver) -> IdentityDriver {
self.identityDriver = identityDriver
return self.identityDriver
}

public func storage() -> StorageDriver {
return self.storageDriver
}

public func setStorage(storageDriver: StorageDriver) -> StorageDriver {
self.storageDriver = storageDriver
return self.storageDriver
}
public func getAccountInfo<T>(account: PublicKey, decodedTo: T.Type, onComplete: @escaping (Result<BufferInfo<T>, Error>) -> Void){

public func getAccountInfo<T>(account: PublicKey, decodedTo: T.Type, onComplete: @escaping (Result<BufferInfo<T>, Error>) -> Void) {
return self.connection.getAccountInfo(account: account, decodedTo: T.self, onComplete: onComplete)
}
public func getMultipleAccounts<T>(accounts: [PublicKey], decodedTo: T.Type, onComplete: @escaping (Result<[BufferInfo<T>?], Error>) -> Void){

public func getMultipleAccounts<T>(accounts: [PublicKey], decodedTo: T.Type, onComplete: @escaping (Result<[BufferInfo<T>?], Error>) -> Void) {
return self.connection.getMultipleAccountsInfo(accounts: accounts, decodedTo: T.self, onComplete: onComplete)
}
public func sendTransaction(serializedTransaction: String, onComplete: @escaping(Result<TransactionID, IdentityDriverError>) -> Void){

public func sendTransaction(serializedTransaction: String, onComplete: @escaping(Result<TransactionID, IdentityDriverError>) -> Void) {
self.identityDriver.sendTransaction(serializedTransaction: serializedTransaction, onComplete: onComplete)
}
public func confirmTransaction(signature: String, configs: RequestConfiguration?, onComplete: @escaping (Result<SignatureStatus?, Error>) -> Void){

public func confirmTransaction(signature: String, configs: RequestConfiguration?, onComplete: @escaping (Result<SignatureStatus?, Error>) -> Void) {
self.connection.confirmTransaction(signature: signature, configs: configs) { signatureResult in
switch signatureResult {
case .success(let signatures):
Expand All @@ -53,10 +53,10 @@ public class Metaplex {
}
}
}
public func sendAndConfirmTransaction(serializedTransaction: String, configs: RequestConfiguration?, onComplete: @escaping (Result<SignatureStatus?, Error>) -> Void){

public func sendAndConfirmTransaction(serializedTransaction: String, configs: RequestConfiguration?, onComplete: @escaping (Result<SignatureStatus?, Error>) -> Void) {
self.sendTransaction(serializedTransaction: serializedTransaction) { result in
switch result{
switch result {
case .success(let signature):
self.confirmTransaction(signature: signature, configs: configs) { signatureResult in
onComplete(signatureResult)
Expand Down
21 changes: 10 additions & 11 deletions Sources/Metaplex/Modules/nfts/NftClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,44 @@ import Solana

public class NftClient {
let metaplex: Metaplex
public init(metaplex: Metaplex){

public init(metaplex: Metaplex) {
self.metaplex = metaplex
}

public func findNftByMint(mintKey: PublicKey, onComplete: @escaping (Result<NFT, OperationError>) -> Void) {
let operation = FindNftByMintOnChainOperationHandler(metaplex: self.metaplex)
operation.handle(operation: FindNftByMintOperation.pure(.success(mintKey))).run {
onComplete($0)
}
}

public func findNftByMintList(mintKeys: [PublicKey], onComplete: @escaping (Result<[NFT?], OperationError>) -> Void) {
let operation = FindNftsByMintListOnChainOperationHandler(metaplex: self.metaplex)
operation.handle(operation: FindNftsByMintListOperation.pure(.success(
mintKeys
))).run { onComplete($0) }
}

public func findNftsByCreator(creator: PublicKey, position: Int? = 1, onComplete: @escaping (Result<[NFT?], OperationError>) -> Void) {
let operation = FindNftsByCreatorOnChainOperationHandler(metaplex: self.metaplex)
operation.handle(operation: FindNftsByCreatorOperation.pure(.success(
FindNftsByCreatorInput(
creator: creator,
position: position
)))).run{ onComplete($0) }
)))).run { onComplete($0) }
}

public func findNftsByCandyMachine(candyMachine: PublicKey, version: UInt8? = 2, onComplete: @escaping (Result<[NFT?], OperationError>) -> Void) {
let operation = FindNftsByCandyMachineOnChainOperationHandler(metaplex: self.metaplex)
operation.handle(operation: FindNftsByCandyMachineOperation.pure(.success(
FindNftsByCandyMachineInput(
candyMachine: candyMachine,
version: version
)))).run{ onComplete($0) }
)))).run { onComplete($0) }
}



public func findNftsByOwner(mintKeys: PublicKey, onComplete: @escaping (Result<[NFT?], OperationError>) -> Void) {

}
}
Loading