Skip to content

Commit

Permalink
Added toJson method for indexers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesulonimi21 committed Mar 24, 2021
1 parent 4837103 commit 42a9ae7
Show file tree
Hide file tree
Showing 22 changed files with 259 additions and 66 deletions.
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ var indexerClient=IndexerClient(host: "INDEXER_API_ADDRESS", port: "API_PORT", t
indexerClient.lookUpAssetBalances(assetId:14077815).execute(){response in
if response.isSuccessful{
print("success")
print(response.data!.balances![0].amount)

print(response.data!.toJson()!)
}else{
print(response.errorDescription)
}
Expand All @@ -117,31 +116,23 @@ indexerClient.lookUpBlocks(roundNumber: 12471917).execute(){response in

if response.isSuccessful{
print("success")
print(response.data!.genesisHash)
print(response.data!.genesisId)
print(response.data!.rewards!.feeSink)
print(response.data!.round)
print(response.data!.upgradeVote?.upgradeApprove)
print(response.data!.upgradeState?.currentProtocol)

print(response.data!.toJson()!)
}else{
print(response.errorDescription)
}
}

indexerClient.searchForAccounts().assetId(assetId: 14077815).execute(){ response in
if response.isSuccessful{
print(response.data!.accounts!.count)
print(response.data!.toJson()!)
}else{
print(response.errorDescription)
}
}

indexerClient.searchForTransactions().txid(txid:"HPS2AQU26NNVTFIJVBYYZN2P2T73AONKWCS7HPT5JUQEQMXFHMJA").execute(){ response in
if response.isSuccessful{
print(response.data!.transactions![0].confirmedRound)
print(response.data!.transactions![0].txType?.rawValue)
print("success")
print(response.data!.toJson()!)
}else{
print(response.errorDescription)
print("failure")
Expand All @@ -154,7 +145,7 @@ indexerClient.searchForAccounts().assetId(assetId: 14077815).execute(){ response

if response.isSuccessful{
print("success")
print(response.data!.asset!.params!.creator!)
print(response.data!..toJson()!)
}else{
print(response.errorDescription)
print("Error");
Expand All @@ -164,7 +155,7 @@ indexerClient.searchForAccounts().assetId(assetId: 14077815).execute(){ response

indexerClient.searchForAssets().assetId(assetId:14077815).execute(){ response in
if response.isSuccessful{
print(response.data!.asset![0].params!.creator!)
print(response.data!..toJson()!)
}else{
print(response.errorDescription)
print("Error");
Expand Down
145 changes: 130 additions & 15 deletions Sources/swift-algorand-sdk/ExampleCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//var PURESTAKE_ALGOD_API_TESTNET_ADDRESS="https://testnet-algorand.api.purestake.io/ps2";
//var PURESTAKE_ALGOD_API_MAINNET_ADDRESS="https://mainnet-algorand.api.purestake.io/ps2";
//var PURESTAKE_INDEXER_API_ADDRESS="https://testnet-algorand.api.purestake.io/idx2";
//var PURESTAKE_API_KEY="ADRySlL0NK5trzqZGAE3q1xxIqlQdSfk1nbHxTNe";
//var PURESTAKE_API_KEY="";
//var PURESTAKE_API_PORT="443";
//var HACKATHON_API_PORT="9100";
//var HACKATHON_API_ADDRESS="http://hackathon.algodev.network";
Expand Down Expand Up @@ -57,16 +57,137 @@
//
//
////testCreateASA(account.getAddress(),algodClient)
////var data=try! ContractTemplate.readAndVerifyContract(program: [1,32,8,1,-48,15,2,0,-64,-106,-79,2,7,3,-72,23,38,3,32,-2,-68,-96,-69,20,74,90,78,-89,-76,56,-92,104,26,-56,14,108,-95,5,-68,-74,7,-4,86,83,37,-55,86,-107,-10,-94,19,32,-103,-32,115,15,-121,33,36,-25,-55,41,-58,11,-66,50,-54,114,59,-13,-36,55,-27,-29,-19,-111,-31,80,-84,-9,36,-35,85,30,32,2,90,-46,-63,-65,28,-93,-8,19,31,-9,-85,-12,-116,-37,-21,-98,-50,-17,50,105,126,42,107,-36,5,-100,-22,26,89,11,22,49,16,34,18,49,1,35,12,16,50,4,36,18,64,0,25,49,9,40,18,49,7,50,3,18,16,49,8,37,18,16,49,2,33,4,13,16,34,64,0,46,51,0,0,51,1,0,18,49,9,50,3,18,16,51,0,7,41,18,16,51,1,7,42,18,16,51,0,8,33,5,11,51,1,8,33,6,11,18,16,51,0,8,33,7,15,16,16,], numInts: 8, numByteArrays: 3)
////print(data.intBlock[1])
////print(data.intBlock[6])
////print(data.intBlock[5])
////print(data.intBlock[7])
////print(ContractTemplate(prog: [1,32,8,1,-48,15,2,0,-64,-106,-79,2,7,3,-72,23,38,3,32,-2,-68,-96,-69,20,74,90,78,-89,-76,56,-92,104,26,-56,14,108,-95,5,-68,-74,7,-4,86,83,37,-55,86,-107,-10,-94,19,32,-103,-32,115,15,-121,33,36,-25,-55,41,-58,11,-66,50,-54,114,59,-13,-36,55,-27,-29,-19,-111,-31,80,-84,-9,36,-35,85,30,32,2,90,-46,-63,-65,28,-93,-8,19,31,-9,-85,-12,-116,-37,-21,-98,-50,-17,50,105,126,42,107,-36,5,-100,-22,26,89,11,22,49,16,34,18,49,1,35,12,16,50,4,36,18,64,0,25,49,9,40,18,49,7,50,3,18,16,49,8,37,18,16,49,2,33,4,13,16,34,64,0,46,51,0,0,51,1,0,18,49,9,50,3,18,16,51,0,7,41,18,16,51,1,7,42,18,16,51,0,8,33,5,11,51,1,8,33,6,11,18,16,51,0,8,33,7,15,16,16,]).address.description)
////
//
////try! testSplitProgram()
//
////indexerClient.lookUpAccountById(address: "LL2ZGXSHW7FJGOOVSV76RRZ6IGU5ZF4DPCHQ23G7ZLIWCB4WEMIATDBTLY").execute(){response in
////
//// if response.isSuccessful{
////
//// print(response.data!.toJson()!)
//// print(1)
//// }else{
//// print(response.errorDescription)
//// }
////}
////indexerClient.lookUpAccountTransactions(address: "LL2ZGXSHW7FJGOOVSV76RRZ6IGU5ZF4DPCHQ23G7ZLIWCB4WEMIATDBTLY").execute(){response in
//// if response.isSuccessful{
//// print(response.data!.toJson()!)
//// print(2)
//// }else{
//// print(response.errorDescription)
//// }
////}
//
//
////indexerClient.lookUpAccountById(address: "LL2ZGXSHW7FJGOOVSV76RRZ6IGU5ZF4DPCHQ23G7ZLIWCB4WEMIATDBTLY").execute(){response in
////
//// if response.isSuccessful{
////
//// print(response.data!.toJson())
//// print(3)
////
////
//// }else{
//// print(response.errorDescription)
//// }
////}
//
////indexerClient.lookUpAssetBalances(assetId:14077815).execute(){response in
//// if response.isSuccessful{
////
//// print(response.data!.toJson()!)
//// print(4)
//// }else{
//// print(response.errorDescription)
//// }
////}
//
////indexerClient.lookUpAssetById(id:14077815).execute(){response in
////
//// if response.isSuccessful{
//// print(response.data!.toJson()!)
//// print(5)
//// }else{
//// print(response.errorDescription)
//// print("Error");
////
//// }
////}
//
////indexerClient.lookupAssetTransactions(assetId:14077815).execute(){response in
////
//// if response.isSuccessful{
//// print(response.data!.toJson()!)
//// print("6")
////
//// }else{
//// print(response.errorDescription)
//// }
////}
//
////indexerClient.lookUpBlock(roundNumber: 12471917).execute(){response in
////
//// if response.isSuccessful{
////
//// print(response.data!.toJson()!)
//// print(7)
////
//// }else{
//// print(response.errorDescription)
//// }
////}
//
////indexerClient.makeHealthCheck().execute(){ response in
//// if response.isSuccessful{
//// print(response.data!.toJson()!)
//// print(8)
//// }else{
//// print(response.errorDescription)
//// }
////}
//
////
////indexerClient.searchForAccounts().assetId(assetId: 14077815).execute(){ response in
//// if response.isSuccessful{
//// print(response.data!.toJson())
//// print(9)
//// }else{
//// print(response.errorDescription)
//// }
////}
//
////indexerClient.searchForApplications().execute(){ response in
//// if response.isSuccessful{
//// print(response.data!.toJson()!)
//// print(10)
//// }else{
//// print(response.errorDescription)
//// }
////}
//
////indexerClient.searchForAssets()/*.limit(limit:10).unit(unit:"LAT") */.assetId(assetId:14077815).execute(){ response in
//// if response.isSuccessful{
//// print(response.data!.toJson()!)
//// print(11)
//// }else{
//// print(response.errorDescription)
//// print("Error");
//// }
////}
//
////
////indexerClient.searchForTransactions().txid(txid:"HPS2AQU26NNVTFIJVBYYZN2P2T73AONKWCS7HPT5JUQEQMXFHMJA").execute(){ response in
//// if response.isSuccessful{
//// print(response.data!.toJson()!)
//// print(12)
//// }else{
//// print(response.errorDescription)
////
////
//// }
////}
//
//dispatchMain()
//
//
Expand Down Expand Up @@ -570,17 +691,11 @@
//}
//
//public func testLookUpBlock(){
// indexerClient.lookUpBlocks(roundNumber: 12471917).execute(){response in
// indexerClient.lookUpBlock(roundNumber: 12471917).execute(){response in
//
// if response.isSuccessful{
// print("success")
// print(response.data!.genesisHash)
// print(response.data!.genesisId)
// print(response.data!.rewards!.feeSink)
// print(response.data!.round)
// print(response.data!.upgradeVote?.upgradeApprove)
// print(response.data!.upgradeState?.currentProtocol)
//
// }else{
// print(response.errorDescription)
// }
Expand Down
2 changes: 1 addition & 1 deletion Sources/swift-algorand-sdk/model/AccountData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
public class AccountData : Decodable{
public class AccountData : Codable{
public var address:String?

public var amount:Int64?
Expand Down
9 changes: 8 additions & 1 deletion Sources/swift-algorand-sdk/model/AccountResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public class AccountResponse : Decodable {
public class AccountResponse : Codable {

public var account:AccountData?
public var currentRound:Int64?
Expand All @@ -16,5 +16,12 @@ public class AccountResponse : Decodable {
case currentRound = "current-round"
case account = "account"
}

public func toJson()->String?{
var jsonencoder=JSONEncoder()
var classData=try! jsonencoder.encode(self)
var classString=String(data: classData, encoding: .utf8)
return classString
}

}
8 changes: 7 additions & 1 deletion Sources/swift-algorand-sdk/model/AccountsResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
public class AccountsResponse : Decodable {
public class AccountsResponse : Codable {

public var accounts:[AccountData]?
public var currentRound:Int64?
Expand All @@ -17,5 +17,11 @@ public class AccountsResponse : Decodable {
case accounts = "accounts"
case nextToken = "next-token"
}
public func toJson()->String?{
var jsonencoder=JSONEncoder()
var classData=try! jsonencoder.encode(self)
var classString=String(data: classData, encoding: .utf8)
return classString
}

}
2 changes: 1 addition & 1 deletion Sources/swift-algorand-sdk/model/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public class Application :Decodable{
public class Application :Codable{
public var id:Int64?;

public var params:ApplicationParams?
Expand Down
2 changes: 1 addition & 1 deletion Sources/swift-algorand-sdk/model/ApplicationParams.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
public class ApplicationParams:Decodable{
public class ApplicationParams:Codable{
public var approvalProgram:[Int8]?
public var clearStateProgram:[Int8]?
public var creator:String?
Expand Down
9 changes: 7 additions & 2 deletions Sources/swift-algorand-sdk/model/ApplicationResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@
//

import Foundation
public class ApplicationResponse : Decodable{
public class ApplicationResponse : Codable{
public var application: Application?
public var currentRound: Int64?


enum CodingKeys:String,CodingKey{
case application = "application"
case currentRound = "current-round"

}
public func toJson()->String?{
var jsonencoder=JSONEncoder()
var classData=try! jsonencoder.encode(self)
var classString=String(data: classData, encoding: .utf8)
return classString
}
}
9 changes: 8 additions & 1 deletion Sources/swift-algorand-sdk/model/ApplicationsResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import Foundation
public class ApplicationsResponse : Decodable{
public class ApplicationsResponse : Codable{
public var applications: [Application]?
public var currentRound: Int64?
public var nextToken : String?
Expand All @@ -16,4 +16,11 @@ public class ApplicationsResponse : Decodable{
case currentRound = "current-round"
case nextToken = "next-token"
}

public func toJson()->String?{
var jsonencoder=JSONEncoder()
var classData=try! jsonencoder.encode(self)
var classString=String(data: classData, encoding: .utf8)
return classString
}
}
8 changes: 8 additions & 0 deletions Sources/swift-algorand-sdk/model/AssetBalancesResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ public class AssetBalancesResponse:Codable{
case currentRound="current-round"
case nextToken="next-token"
}

public func toJson()->String?{
var jsonencoder=JSONEncoder()
var classData=try! jsonencoder.encode(self)
var classString=String(data: classData, encoding: .utf8)
return classString
}

}
7 changes: 7 additions & 0 deletions Sources/swift-algorand-sdk/model/AssetResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ public class AssetResponse:Codable{
case asset="asset"
case currentRound="current-round"
}

public func toJson()->String?{
var jsonencoder=JSONEncoder()
var classData=try! jsonencoder.encode(self)
var classString=String(data: classData, encoding: .utf8)
return classString
}
}

6 changes: 6 additions & 0 deletions Sources/swift-algorand-sdk/model/AssetsResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ public class AssetsResponse:Codable{
case currentRound="current-round"
case nextToken="next-token"
}
public func toJson()->String?{
var jsonencoder=JSONEncoder()
var classData=try! jsonencoder.encode(self)
var classString=String(data: classData, encoding: .utf8)
return classString
}
}
Loading

0 comments on commit 42a9ae7

Please sign in to comment.