Giter VIP home page Giter VIP logo

arkkit's Introduction

ARKKit

a macOS & iOS Swift Framework for Ark.io.

ARKKit Version BUILD License: MIT

Swift Version Platform Platform Xcode Version

Platform Platform Platform

What is ARKKit?

ARKKit is wrapper for interacting with the Ark Ecosystem.
It is written purely in Swift 4.0, using no external dependencies or libraries.
This allows for a quick, easy, and dependecy-free integration into your Computer, Server, or iDevice project!

Articles

Todo:

  • Implement URLSession
  • Signature/Cryptographic Integration
  • Transaction Creation & Signing
  • Voting
  • Delegate Registration
  • Restructure API
  • Your suggestions!

Usage

samples:

Check an account on mainnet or devnet:

  let devAccount = ARK.dev.account(from: "DHQ4Fjsyiop3qBR4otAjAu6cBHkgRELqGA")  
  let mainAccount = ARK.main.account(from: "AZreeHxX23s4jttL3ML8n6A2aLrwHPfVGZ")  

returning:

Account(username: nil,
        address: DHQ4Fjsyiop3qBR4otAjAu6cBHkgRELqGA,
        balance: 1901565824885,
        unconfirmedBalance: 1901565824885,
        publicKey: 0275776018638e5c40f1b922901e96cac2caa734585ef302b4a2801ee9a338a456,
        unconfirmedSignature: nil,
        secondSignature: nil,
        secondPublicKey: Optional("03ad2a481719c80571061f0c941d57e91c928700d8dd132726edfc0bf9c4cb2869"),
        multisignatures: Optional([]), unconfirmedMultisignatures: Optional([])) 

See all of the blocks on mainnet or devnet:

  let allDevBlocks = ARK.dev.allBlocks()  
  let allMainBlocks = ARK.main.allBlocks()  

returning:

allBlocks = [
    Block(id: 711675773079271579,
          version: 0, timestamp: 13737984,
          height: 1015588,
          previousBlock: 11596800618568825334,
          numberOfTransactions: 0,
          totalAmount: 0,
          totalFee: 0,
          reward: 200000000,
          payloadLength: 0,
          payloadHash: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855,
          generatorPublicKey: 03bd4f16e39aaba5cba6a87b7498b08ce540f279be367e68ae96fb05dfabe203ad,
          generatorId: DBi2HdDY8TqMCD2aFLVomEF92gzeDmEHmR,
          blockSignature: 3045022100a9e3381e506daa6f050f2ebdb0de584a3f7f9a7b7caba03ff2874d086e8911250220146719ba882ebd9847857a8b681b932616f1544008cc0a02e48613fd75df256d,
          confirmations: 1,
          totalForged: 200000000),
    Block(id: 11596800618568825334,
          version: 0,
          timestamp: 13737976,
          height: 1015587,
          previousBlock: 16455111908480150750,
          numberOfTransactions: 0,
          totalAmount: 0,
          totalFee: 0,
          reward: 200000000,
          payloadLength: 0,
          payloadHash: ............

or check the current block-height of a given network:

  let currentBlockHeight = Block.height(on: .dev)   /* returned "1015611" */

Cross-convert price values between standard(human-readable), and ѦRK:

  let standardPrice = Price.arkAmount(550000000).toStandard   /* returns "5.5" */
  let arkPrice = Price.amount(5.5).toArk  /* returns "550000000" */

Check the status of a Node/Peer:

  let statusOfPeer = ARK.dev.statusOfPeerWith(ip: "35.188.148.247")  

returns:

  statusOfIP = Peer(ip: 35.188.148.247,
                    port: 4002,
                    version: 1.1.0,
                    os: linux4.10.0-32-generic,
                    height: 1015589,
                    status: OK,
                    delay: 263) 

Check for network Peers/Seeds:

  let allNetworkSeeds = ARK.dev.allSeeds()  

returning:

 peers = [
      "167.114.29.51",
      "167.114.29.52",
      "167.114.29.53",
      "35.188.148.247",
      .................
      ] 

Get all of the transaction on a given network:

  let allTransactions = ARK.dev.allTransactions()  

returning:

allTransactions = [
    Transaction(id: e40ce11cab82736da1cc91191716f3c1f446ca7b6a9f4f93b7120ef105ba06e8,
                blockID: 13149578060728881902,
                type: 0,
                timestamp: 0,
                amount: 12500000000000000,
                fee: 0,
                senderID: DUFeXjJmYt1mWY3auywA1EQSqfCv5kYYfP,
                recipientID: DGihocTkwDygiFvmg6aG8jThYTic47GzU9,
                senderPublicKey: Optional("03cb7bca143376721d0e9e3f3ccb0dc2e7e8470c06e630c3cef73f03e309b558ad"),
                signature: 3044022016ecdf3039e69514c7d75861b22fc076496b61c07a1fcf793dc4f5c76fa0532b0220579c4c0c9d13720f9db5d9df29ed8ceab0adc266c6c160d612d4894dc5867eb1,
                asset: Optional(ARKKit_macOSTests.TransactionAsset.Delegate(username: nil, publicKey: nil)),
                vendorField: nil,
                confirmations: 1015646),
    Transaction(id: eb0146ac79afc228f0474a5ae1c4771970ae7880450b998c401029f522cd8a21,]
                blockID: 13149578060728881902,
                type: 2,
                timestamp: 0,
                amount: 0,
                fee: 0,
                senderID: DNL81CT6WNG1PHjobBmLvKwLV3UUscBymB,
                recipientID: nil,
                senderPublicKey: Optional("03e5b39a83e6c7c952c5908089d4524bb8dda93acc2b2b953247e43dc4fe9aa3d1"),
                signature: 3045022100e3e38811778023e6f17fefd447f179d45ab92c398c7cfb1e34e2f6e1b167c95a022070c36439ecec0fc3c43850070f29515910435d389e059579878d61b5ff2ea337,
                asset: Optional(ARKKit_macOSTests.TransactionAsset.Delegate(username: genesis_1,
                                                                            publicKey: 03e5b39a83e6c7c952c5908089d4524bb8dda93acc2b2b953247e43dc4fe9aa3d1)),
                vendorField: nil,
                confirmations: 1015646),
    .......................
    ]

or get the total number of transactions on a given network:

  let totalTransactions = ARK.main.totalNumberOfTransactions()  /* returned "137761" */

Recommended Resources

More Ѧrk Developer-Language Integrations:

Tip Jar

ѦRK [Ѧ]: AZreeHxX23s4jttL3ML8n6A2aLrwHPfVGZ

DѦRK [DѦ]: DHQ4Fjsyiop3qBR4otAjAu6cBHkgRELqGA

arkkit's People

Contributors

lemamichael avatar sleepdefic1t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

arkkit's Issues

Improvements/feedback

I have spent some time working with this framework in attempt to use it in the monitoring app. In the end, there were several issues preventing me from using this framework for a production ready app.This lead meyme to write my own framework SwiftyArk. I wanted to share with you some of the feedback I have.

  1. The main issue I had with the app is the networking architecture. You are making asynchronous network calls to the ark node, but the method signatures are synchronous:
let allMainBlocks = ARK.main.allBlocks() 

is a synchronous assignment with no error handling. However, behind the scenes this is an asynchronous call that has the potential for many errors, which are never handled. It is not documentation that this assignment will fail, or result in an empty array. The swift way to do this is with a completion handler and error handling:

ARK.main.allBlock() { (error, blocks) in
        if let aError = error {
              /// handle error
        }
        if let allBlocks = blocks {
             // all blocks are returned here and unwrapped
        }
 }

The difference between the two (besides error handling) is the second option returns data in an asynchronous manner. In your API, the assignment occurs on the main thread and will block the entire app until it returns or errrors out.

  1. The networking of this app boils down to using NSString.(contentsOf:URL:) to grab raw data and convert it to a UTF8 string. This api wasn't designed for being used for networking, but rather read files from inside your app. It is not documented anywhere the error handling and doesn't give you any access to HTTP data (headers, statusCodes etc). You should look into using URLSession as it is the primary function for networking in iOS/mac apps. This will also allow you to extend your API to allow for PUT and POST operations, something NSString.(contentsOf:URL:)

  2. Your data types are not very swift like. You declare your internal properties as variables, rather than constants. There is nothing in the API to suggest the types should be modified, so why not make them immutable?

  3. More on the data types, the initialization of them is very un-swift like and leads to several issues. Data types like Account do not have any initializers, but rather assignments in an protocol (which I will get to). This is not very safe as these are declared as ** non-optional options**:

public struct Account: Accountable {
    public var  address: String!
    /// ...

You are basically saying "I guarantee there will be an address for an Account, but you do not provide (or prevent) any initialization, so its not safe:

let account = Account()
let example = account.balance * 10
// CRASH!

I would recommend you get rid of the assignment inside of a protocol and move it directly to an initializer, make the types immutable constants/optionals and prevent any unintentional initialization. Swift 4 introduced the Decodable protocol to direct add an initializer from json. Using it in conjunction with URLSession is a winning combo.

  1. This last one is more of a style comment, but I have noticed you use Swift types in a non-typical way. Your primary API manager is an enum when it should be a class/struct. You also create protocols for each data type (Accountable, Delegable etc) when they essentially do the same thing for each data type. You could create one data protocol that would apply to all datatypes which can be decoded from son (like Decodable)

I hope this helps you. I want this framework to be great. You are doing a lot of great things for the community and I would very much like to see all the features you hope to implement. If you want some inspiration, you can check out SwiftyArk or if you need any advice: [email protected]

Andrew

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.