Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
bin
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Echo-ios-framework (echo-ios-framework)

Pure Swift Echo framework for iOS mobile development. Can be used to work with accounts, transactions and contracts in Swift, and to easily obtain data from the blockchain via public apis.

Install

This framework can be obtained through CocoaPods:

pod 'EchoFramework'

Setup

For setup framework use this simple code:

// Create and Setup framework main class
let echo = ECHO(settings: Settings(build: {
    /** Here you can put your custom settings for our framework
        Example: 
        Custom api options which can be used
    */
    $0.apiOptions = [.accountHistory, .database, .networkBroadcast]
}))

// Start framwork. Connect to nodes and setup public apis
echo.start { (result) in
    switch result {
    case .success(let result):
        print(result)
    case .failure(let error):
        print(error)
}

Usage

There are simple examples of usage framework

Accounts

Login

func login() {
    echo.isOwnedBy(name: "some name", wif: "some wif") { (result) in
        print(result)
    }
}

Info

func getInfo() {
    let name = "some name"

    echo.getAccount(nameOrID: name) { (result) in
        print("Account \(result)")
    }

    echo.getBalance(nameOrID: name, asset: "1.3.1") { (result) in
        print("Balance \(result)")
    }

    echo.getBalance(nameOrID: name, asset: nil) { (result) in
        print("Assets with balances \(result)")
    }

    echo.isAccountReserved(nameOrID: name) { (result) in
        print("Is reserved \(result)")
    }
}

History

func getHistory() {
    echo.getAccountHistroy(
        nameOrID: "some ID", 
        startId: "1.11.0", 
        stopId: "1.11.0", 
        limit: 100
    ) { (result) in
        switch result {
        case .success(let history):
            print(history)
            for element in history {
                print(element)
            }
        case .failure(let error):
            print(error)
        }
    }
}

Subscribe to account

func setSubscriber() {
    let name = "some name"

    echo.subscribeToAccount(nameOrId: name, delegate: self)
}

extension YourClass: SubscribeAccountDelegate {
    func didUpdateAccount(userAccount: UserAccount) {
        print("Account updated \(userAccount)")
    }
}

Change keys

func changeKeys() {
    echo.changeKeys(
        oldWIF: "your old wif", 
        newWIF: "your new wif", 
        name: "some name",
        sendCompletion: { (result) in
            switch result {
            case .success(let success):
                print("Success send transaction")
            case .failure(let error):
                print("Error while sending transaction")
            }
        }, 
        confirmNoticeHandler: { (notice) in
            switch notice {
            case .success(let success):
                print("Transaction confirmed")
            case .failure(let error):
                print("Transaction didn't confirmed")
            }
        }
    )
}

Fee for transfer

func feeForTransfer() {
    echo.getFeeForTransferOperation(
        fromNameOrId: "some name", 
        toNameOrId: "some name", 
        amount: 300, 
        asset: "1.3.0", 
        assetForFee: nil
    ) { (result) in                                
        switch result {
        case .success(let fee):
            print(fee)
        case .failure(let error):
            print(error)
        }
    }
}

Transfer

funс transfer() {
    echo.sendTransferOperation(
        fromNameOrId: "some name",
        wif: "some wif",
        toNameOrId: "some name",
        amount: 300,
        asset: "1.3.0",
        assetForFee: nil,
        sendCompletion: { (result) in
            switch result {
            case .success(let success):
                print("Success send transaction")
            case .failure(let error):
                print("Error while sending transaction")
            }
        }, 
        confirmNoticeHandler: { (notice) in
            switch notice {
            case .success(let success):
                print("Transaction confirmed")
            case .failure(let error):
                print("Transaction didn't confirmed")
            }
        }
    )
}

Assets

Create asset

func createAsset() {
    var asset = Asset("")
    asset.symbol = "some symbol"
    asset.precision = 4
    asset.issuer = Account("some account id")
    asset.predictionMarket = false

    let price = Price(
        base: AssetAmount(amount: 1, asset: Asset("1.3.0")), 
        quote: AssetAmount(amount: 1, asset: Asset("1.3.1"))
    )

    asset.options = AssetOptions(
        maxSupply: 100000,
        marketFeePercent: 0,
        maxMarketFee: 0,
        issuerPermissions: AssetOptionIssuerPermissions.overrideAuthority,
        flags: AssetOptionIssuerPermissions.committeeFedAsset.rawValue,
        coreExchangeRate: price,
        description: "some description"
    )

    echo.createAsset(
        nameOrId: "some name", 
        wif: "some wif", 
        asset: asset,
        sendCompletion: { (result) in
            switch result {
            case .success(let success):
                print("Success send transaction")
            case .failure(let error):
                print("Error while sending transaction")
            }
        }, 
        confirmNoticeHandler: { (notice) in
            switch notice {
            case .success(let success):
                print("Transaction confirmed")
            case .failure(let error):
                print("Transaction didn't confirmed")
            }
        }
    )
}

Issue asset

func issueAsset() {
    echo.issueAsset(
        issuerNameOrId: "some name",
        wif: "some wif",
        asset: "1.3.87",
        amount: 1,
        destinationIdOrName: "some name"
        sendCompletion: { (result) in
            switch result {
            case .success(let success):
                print("Success send transaction")
            case .failure(let error):
                print("Error while sending transaction")
            }
        }, 
        confirmNoticeHandler: { (notice) in
            switch notice {
            case .success(let success):
                print("Transaction confirmed")
            case .failure(let error):
                print("Transaction didn't confirmed")
            }
        }
    )
}

Contracts

Create contract

func createContract() {
    let byteCode = "some bytecode"

    echo.createContract(
        registrarNameOrId: "some name",
        wif: "some wif",
        assetId: "1.3.0",
        amount: nil,
        assetForFee: nil,
        byteCode: byteCode,
        supportedAssetId: nil,
        ethAccuracy: nil,
        parameters: nil,
        sendCompletion: { (result) in
            switch result {
            case .success(let success):
                print("Success send transaction")
            case .failure(let error):
                print("Error while sending transaction")
            }
        }, 
        confirmNoticeHandler: { (notice) in
            switch notice {
            case .success(let success):
                print("Transaction confirmed")
            case .failure(let error):
                print("Transaction didn't confirmed")
            }
        }
    )
}

Call contract

func callContract() {
    echo.callContract(
        registrarNameOrId: "some name",
        wif: "some wif",
        assetId: "1.3.0",
        assetForFee: nil,
        contratId: "1.16.1",
        methodName: "some name",
        methodParams: [],
        sendCompletion: { (result) in
            switch result {
            case .success(let success):
                print("Success send transaction")
            case .failure(let error):
                print("Error while sending transaction")
            }
        }, 
        confirmNoticeHandler: { (notice) in
            switch notice {
            case .success(let success):
                print("Transaction confirmed")
            case .failure(let error):
                print("Transaction didn't confirmed")
            }
        }
    )
}

Query contract

func queryContract() {
    echo.queryContract(
        registrarNameOrId: "some name", 
        assetId: "1.3.0", 
        contratId: "1.16.1", 
        methodName: "some name", 
        methodParams: []
    ) { (result) in
        switch result {
        case .success(let success):
            print(success)
        case .failure(let error):
            print(error)
        }
    }
}