Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
Open
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
73 changes: 73 additions & 0 deletions Sources/SwiftyEOS/Models/ActionModels.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//
// ActionModels.swift
// SwiftyEOS
//
// Created by ysoftware on 27/12/2018.
// Copyright © 2018 ProChain. All rights reserved.
//

import Foundation

// After reaching sequence number of 2^32, sequence value is being represented as a string instead of int
// This is used to make sure both options work
typealias ActionSeq = AnyCodable

// Use intValue to unpack sequence number as Int
extension ActionSeq {
var intValue:Int {
if let i = value as? Int { return i }
else if let s = value as? String, let i = Int(s) { return i }
return 0 // fall back
}
}

struct ActionsResult: Codable {
let actions:[ActionReceipt]
let lastIrreversibleBlock:Int
}

struct ActionReceipt: Codable {
let blockNum:Int
let globalActionSeq:ActionSeq
let accountActionSeq:ActionSeq
let blockTime:String
let actionTrace: ActionTrace
}

struct ActionTrace: Codable {
let receipt:Receipt
let act:ActionDetails
let contextFree:Bool
let elapsed:Int
let console:String
let trxId:String
let blockNum:Int
let blockTime:String
let producerBlockId:String? // can be null on a testnode
let accountRamDeltas:[ActionRamDelta]
let inlineTraces:[ActionTrace]
let except:AnyCodable?
}

struct ActionRamDelta: Codable {
let account:String
let delta:Int
}

struct Receipt: Codable {
let receiver:String
let actDigest:String
let globalSequence: ActionSeq
let recvSequence:Int
let authSequence:[AnyCodable]
let codeSequence:Int
let abiSequence:Int
}

struct ActionDetails: Codable {
let authorization: [Authorization]
let data: AnyCodable
let account: String
let name: String
let hexData: String?
}
8 changes: 8 additions & 0 deletions Sources/SwiftyEOS/Network/History/EOSRPC+History.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ extension EOSRPC {
let router = HistoryRouter(endpoint: .GetKeyAccounts(pub: pub))
internalRequest(router: router, completion: completion)
}

func getActions(accountName: String, position: Int, offset: Int,
completion: @escaping (_ result: ActionsResult?, _ error: Error?) -> Void) {
let router = HistoryRouter(endpoint: .GetActions(accountName: accountName,
pos: position,
offset: offset))
internalRequest(router: router, completion: completion)
}
}
10 changes: 8 additions & 2 deletions Sources/SwiftyEOS/Network/History/HistoryRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation

enum HistoryEndpoint {
case GetKeyAccounts(pub: String)
case GetActions(accountName: String, pos: Int, offset: Int)
}

class HistoryRouter: BaseRouter {
Expand All @@ -20,13 +21,15 @@ class HistoryRouter: BaseRouter {

override var method: HTTPMethod {
switch endpoint {
case .GetKeyAccounts: return .post
case .GetKeyAccounts: return .post
case .GetActions: return .post
}
}

override var path: String {
switch endpoint {
case .GetKeyAccounts: return "/history/get_key_accounts"
case .GetActions: return "/history/get_actions"
}
}

Expand All @@ -37,11 +40,14 @@ class HistoryRouter: BaseRouter {
}

override var body: Data? {
let encoder = JSONEncoder()
switch endpoint {
case .GetKeyAccounts(let pub):
let encoder = JSONEncoder()
let jsonData = try! encoder.encode(["public_key": "\(pub)"])
return jsonData
case .GetActions(let accountName, let pos, let offset):
let data = ["account_name": accountName, "pos": "\(pos)", "offset": "\(offset)"]
return try! encoder.encode(data)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions SwiftyEOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
27FC751520BD247700435C50 /* AnyDecodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27FC751220BD247700435C50 /* AnyDecodable.swift */; };
27FC751620BD247700435C50 /* AnyCodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27FC751320BD247700435C50 /* AnyCodable.swift */; };
27FC751720BD247700435C50 /* AnyEncodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 27FC751420BD247700435C50 /* AnyEncodable.swift */; };
71C2439B21D4D14F00E86F64 /* ActionModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71C2439A21D4D14F00E86F64 /* ActionModels.swift */; };
/* End PBXBuildFile section */

/* Begin PBXBuildRule section */
Expand Down Expand Up @@ -220,6 +221,7 @@
27FC751220BD247700435C50 /* AnyDecodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyDecodable.swift; sourceTree = "<group>"; };
27FC751320BD247700435C50 /* AnyCodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyCodable.swift; sourceTree = "<group>"; };
27FC751420BD247700435C50 /* AnyEncodable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AnyEncodable.swift; sourceTree = "<group>"; };
71C2439A21D4D14F00E86F64 /* ActionModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionModels.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -567,6 +569,7 @@
27FC74F920BD10B900435C50 /* Models */ = {
isa = PBXGroup;
children = (
71C2439A21D4D14F00E86F64 /* ActionModels.swift */,
27FC74FA20BD10B900435C50 /* ChainModels.swift */,
27FC74FB20BD10B900435C50 /* BigInt.swift */,
2783777920F8A308003CC8DB /* Error.swift */,
Expand Down Expand Up @@ -793,6 +796,7 @@
2720E71B21257D9E00643AE6 /* TransactionUtil.swift in Sources */,
27FC750E20BD10B900435C50 /* main.swift in Sources */,
2730778E21916C1B0099E6B0 /* sha3.c in Sources */,
71C2439B21D4D14F00E86F64 /* ActionModels.swift in Sources */,
27FC750D20BD10B900435C50 /* BigInt.swift in Sources */,
27FC750C20BD10B900435C50 /* ChainModels.swift in Sources */,
27FC750920BD10B900435C50 /* KeyPair.swift in Sources */,
Expand Down