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

GraphQL Provider implementation #54

Merged
merged 42 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b83556d
Initial Apollo Integration
MarcoDotIO Dec 20, 2023
f09cc7f
Implement getChainIdentifier
MarcoDotIO Dec 20, 2023
fdb6090
Implement getCheckpoint function for GraphQL
MarcoDotIO Dec 20, 2023
7b87197
Implement getCheckpoints GraphQL function
MarcoDotIO Dec 20, 2023
48f56b7
Implement QueryEvent GraphQL Endpoint
Jan 9, 2024
122b706
Implement GetLatestCheckpointSequenceNumber GraphQL query endpoint
Jan 9, 2024
7956414
Implement GetCoins endpoint
Jan 10, 2024
435d531
Implement GetBalance endpoint, fix issue with building
Jan 10, 2024
7fb2b11
Implement GetAllBalances endpoint
Jan 10, 2024
2285804
Implement total supply endpoint
Jan 10, 2024
46c7c12
Implement updated schema and queries
Jan 14, 2024
15b7143
Implement fixes for Graph QL provider functions
Jan 14, 2024
af07ec9
Implement GetMoveFunctionArgTypes, fix other queries for address name
Jan 17, 2024
66351e9
Implement E2E test class for GraphQL provideer, getCoins test impleme…
Jan 18, 2024
7820c16
Implement test for getAllCoins
Jan 18, 2024
690cfb9
Implement getBalance GraphQL Provider test
Jan 18, 2024
937c1af
Implement getAllBalances GraphQL Provider test
Jan 18, 2024
9f02e48
Implement getCoinMetadata GraphQL Provider test
Jan 18, 2024
66fc3f0
Fix issue and implement test for GraphQL getTotalSupply
Jan 18, 2024
d381082
Implement test for getMoveFunctionArgTypes GraphQL Function
Jan 18, 2024
4f204a3
I'm a dingus, fix test and GraphQL function with move module arg types
Jan 18, 2024
9ffe55f
Implement getNormalizedMoveFunction function and test
Jan 18, 2024
2613f50
Implement getNormalizedMoveModulesByPackage function and test
Jan 19, 2024
250ac79
Implement getNormalizedMoveModule function and test
Jan 19, 2024
c47059f
Implement getNormalizedMoveStruct function and test
Jan 19, 2024
dfae4e2
Implement getOwnedObjects function and test
Jan 22, 2024
04be4b0
Implement getObject function and test
Jan 22, 2024
1161949
Implement ProtocolConfig function and test
Jan 29, 2024
45634a4
Implement tests for checkpoint and checkpoints
Jan 29, 2024
876609c
Implement getTotalTransactionBlock function and test
Jan 29, 2024
a664a5c
Implement getReferenceGasPrice function and test
Jan 29, 2024
eff1612
Implement getLatestCheckpointSequenceNumber function and test
Jan 29, 2024
c6fd484
Implement getChainIdentifier test
Jan 30, 2024
59b8b7d
Implement getValidatorsApy function and test, fix issue with RPC prov…
Jan 30, 2024
461039e
Implement multiGetObject function and test
Jan 30, 2024
cbc0fea
Implement tryGetPastObject function and test
Jan 31, 2024
ae2ad0c
Fix tryGetPastObject test.
Jan 31, 2024
49fab86
Implement lint for Checkpoint objects
Feb 5, 2024
4c0643a
Implement lint for coin objects
Feb 5, 2024
775e5c4
Implement lint for Cyrptography objects
Feb 5, 2024
9f6e31b
Implement lint for GraphQL core function objects
Feb 5, 2024
44a8d34
Implement lint for GraphQL Provider test
Feb 5, 2024
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
18 changes: 18 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
"version" : "0.6.7"
}
},
{
"identity" : "apollo-ios",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apollographql/apollo-ios.git",
"state" : {
"revision" : "7e28eb75e9970edaba346a3c1eab1f8fc479a04d",
"version" : "1.7.1"
}
},
{
"identity" : "bigint",
"kind" : "remoteSourceControl",
Expand Down Expand Up @@ -63,6 +72,15 @@
"version" : "3.1.0"
}
},
{
"identity" : "sqlite.swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/stephencelis/SQLite.swift.git",
"state" : {
"revision" : "7a2e3cd27de56f6d396e84f63beefd0267b55ccb",
"version" : "0.14.1"
}
},
{
"identity" : "swiftyjson",
"kind" : "remoteSourceControl",
Expand Down
6 changes: 4 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ let package = Package(
.package(url: "https://github.com/Flight-School/AnyCodable", from: "0.6.0"),
.package(url: "https://github.com/tesseract-one/Bip39.swift.git", from: "0.1.1"),
.package(url: "https://github.com/web3swift-team/web3swift.git", from: "3.2.0"),
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0")
.package(url: "https://github.com/auth0/JWTDecode.swift", from: "3.1.0"),
.package(url: "https://github.com/apollographql/apollo-ios.git", .upToNextMajor(from: "1.0.0"))
],
targets: [
.target(
Expand All @@ -31,7 +32,8 @@ let package = Package(
.product(name: "AnyCodable", package: "AnyCodable"),
.product(name: "Bip39", package: "Bip39.swift"),
.product(name: "web3swift", package: "web3swift"),
.product(name: "JWTDecode", package: "JWTDecode.swift")
.product(name: "JWTDecode", package: "JWTDecode.swift"),
.product(name: "Apollo", package: "apollo-ios")
],
path: "Sources"
),
Expand Down
46 changes: 0 additions & 46 deletions [email protected]

This file was deleted.

46 changes: 0 additions & 46 deletions [email protected]

This file was deleted.

22 changes: 22 additions & 0 deletions Sources/SuiKit/Extensions/AnyHashable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// File.swift
//
//
// Created by Marcus Arnett on 1/17/24.
//

import Foundation

extension AnyHashable: ScalarType, OutputTypeConvertible, AnyScalarType {
public init(_jsonValue value: JSONValue) throws {
self = value
}

public static var _asOutputType: ApolloAPI.Selection.Field.OutputType {
.scalar(AnyHashable.self)
}

public var _jsonValue: ApolloAPI.JSONValue {
self
}
}
20 changes: 20 additions & 0 deletions Sources/SuiKit/Extensions/DateFormatter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// File.swift
//
//
// Created by Marcus Arnett on 1/29/24.
//

import Foundation

extension DateFormatter {
static func unixTimestamp(from dateString: String) -> Int? {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
guard let date = dateFormatter.date(from: dateString) else {
return nil
}
return Int(date.timeIntervalSince1970 * 1_000)
}
}
2 changes: 2 additions & 0 deletions Sources/SuiKit/Protocols/Sui/ConnectionProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public protocol ConnectionProtocol {
/// Optional URL for a faucet service to obtain tokens.
/// Default is nil, meaning no faucet is configured.
var faucet: String? { get }

var graphql: String? { get }

/// Optional URL for a WebSocket connection.
/// Default is nil, meaning no WebSocket is configured.
Expand Down
3 changes: 3 additions & 0 deletions Sources/SuiKit/Types/Enums/Errors/SuiError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,7 @@ public enum SuiError: Error, Equatable {

/// The Kiosk Data is invalid.
case invalidKioskData

/// The result for the GraphQL query is missing
case missingGraphQLData
}
2 changes: 1 addition & 1 deletion Sources/SuiKit/Types/Enums/Objects/ObjectOwner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import Foundation
import SwiftyJSON

/// `ObjectOwner` represents the possible types of ownership for objects.
public enum ObjectOwner: KeyProtocol {
public enum ObjectOwner: KeyProtocol, Equatable {
/// Represents an object owned by an address. The associated value is a `String` containing the address.
case addressOwner(String)

Expand Down
46 changes: 45 additions & 1 deletion Sources/SuiKit/Types/Enums/Objects/RawData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,57 @@ import SwiftyJSON
///
/// This enum allows for either a `MoveObjectRaw` or `PackageRaw` data type, capturing
/// the raw information for either a Move object or a package object.
public enum RawData {
public enum RawData: Equatable {
/// Represents raw data for a Move object. The associated value is a `MoveObjectRaw` containing the Move object's raw data.
case moveObject(MoveObjectRaw)

/// Represents raw data for a package object. The associated value is a `PackageRaw` containing the package object's raw data.
case packageObject(PackageRaw)

public init(graphql: TryGetPastObjectQuery.Data.Object.AsMoveObject, version: String) {
self = .moveObject(
MoveObjectRaw(
bcsBytes: JSON(graphql.ifShowBcs!.contents!.bcs).stringValue,
hasPublicTransfer: graphql.ifShowBcs!.hasPublicTransfer,
type: graphql.ifShowBcs!.contents!.type.repr,
version: version
)
)
}

public init(graphql: GetOwnedObjectsQuery.Data.Address.ObjectConnection.Node.AsMoveObject, version: String) {
self = .moveObject(
MoveObjectRaw(
bcsBytes: JSON(graphql.ifShowBcs!.contents!.bcs).stringValue,
hasPublicTransfer: graphql.ifShowBcs!.hasPublicTransfer,
type: graphql.ifShowBcs!.contents!.type.repr,
version: version
)
)
}

public init(graphql: MultiGetObjectsQuery.Data.ObjectConnection.Node.AsMoveObject, version: String) {
self = .moveObject(
MoveObjectRaw(
bcsBytes: JSON(graphql.ifShowBcs!.contents!.bcs).stringValue,
hasPublicTransfer: graphql.ifShowBcs!.hasPublicTransfer,
type: graphql.ifShowBcs!.contents!.type.repr,
version: version
)
)
}

public init(graphql: GetObjectQuery.Data.Object.AsMoveObject, version: String) {
self = .moveObject(
MoveObjectRaw(
bcsBytes: JSON(graphql.ifShowBcs!.contents!.bcs).stringValue,
hasPublicTransfer: graphql.ifShowBcs!.hasPublicTransfer,
type: graphql.ifShowBcs!.contents!.type.repr,
version: version
)
)
}

/// Parses a `JSON` object to determine the type of raw data it contains and returns a corresponding `RawData` instance.
///
/// - Parameters:
Expand Down
58 changes: 57 additions & 1 deletion Sources/SuiKit/Types/Enums/Objects/SuiParsedData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,69 @@ import SwiftyJSON
///
/// The enum handles two main types of parsed data: `MoveObject` and `MovePackage`, which represent
/// different kinds of data structures commonly used in Sui-related operations.
public enum SuiParsedData {
public enum SuiParsedData: Equatable {
/// Represents a parsed Move object. The associated value is a `MoveObject` that holds the parsed fields and other relevant data for a Move object.
case moveObject(MoveObject)

/// Represents a parsed Move package. The associated value is a `MovePackage` containing the disassembled or decomposed package information.
case movePackage(MovePackage)

public init(graphql: TryGetPastObjectQuery.Data.Object.AsMoveObject) {
let fields: [String: AnyHashable] = [
"data": graphql.ifShowContent!.contents!.data,
"layout": graphql.ifShowContent!.contents!.type.layout
]
self = .moveObject(
MoveObject(
fields: JSON(fields),
hasPublicTransfer: graphql.ifShowContent!.hasPublicTransfer,
type: graphql.ifShowContent!.contents!.type.repr
)
)
}

public init(graphql: GetOwnedObjectsQuery.Data.Address.ObjectConnection.Node.AsMoveObject) {
let fields: [String: AnyHashable] = [
"data": graphql.ifShowContent!.contents!.data,
"layout": graphql.ifShowContent!.contents!.type.layout
]
self = .moveObject(
MoveObject(
fields: JSON(fields),
hasPublicTransfer: graphql.ifShowContent!.hasPublicTransfer,
type: graphql.ifShowContent!.contents!.type.repr
)
)
}

public init(graphql: MultiGetObjectsQuery.Data.ObjectConnection.Node.AsMoveObject) {
let fields: [String: AnyHashable] = [
"data": graphql.ifShowContent!.contents!.data,
"layout": graphql.ifShowContent!.contents!.type.layout
]
self = .moveObject(
MoveObject(
fields: JSON(fields),
hasPublicTransfer: graphql.ifShowContent!.hasPublicTransfer,
type: graphql.ifShowContent!.contents!.type.repr
)
)
}

public init(graphql: GetObjectQuery.Data.Object.AsMoveObject) {
let fields: [String: AnyHashable] = [
"data": graphql.ifShowContent!.contents!.data,
"layout": graphql.ifShowContent!.contents!.type.layout
]
self = .moveObject(
MoveObject(
fields: JSON(fields),
hasPublicTransfer: graphql.ifShowContent!.hasPublicTransfer,
type: graphql.ifShowContent!.contents!.type.repr
)
)
}

/// Parses a JSON object to determine the type of parsed data and returns an instance of `SuiParsedData`.
///
/// - Parameters:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//

import Foundation
import SwiftyJSON

/// `SuiMoveFunctionArgType` represents the type of an argument in a Move function.
///
Expand All @@ -32,8 +33,34 @@ import Foundation
public enum SuiMoveFunctionArgType: Equatable {
/// The argument is a pure value and doesn't involve any object references.
case pure

/// The argument is an object. The kind of the object (immutable/mutable reference or by value) is specified.
case object(ObjectValueKind)

public init(graphql: GetMoveFunctionArgTypesQuery.Data.Object.AsMovePackage.Module.Function.Parameter) {
self = Self.fromHashable(hash: graphql.signature)
}

public init(graphql: RPC_MOVE_STRUCT_FIELDS.Field.Type_SelectionSet) {
self = Self.fromHashable(hash: graphql.signature)
}

private static func fromHashable(hash: AnyHashable) -> SuiMoveFunctionArgType {
let jsonGraphQL = JSON(hash)

if !(jsonGraphQL["body"]["datatype"].exists()) {
return .pure
}

if jsonGraphQL["ref"].stringValue == "&" {
return .object(.byImmutableReference)
}

if jsonGraphQL["ref"].stringValue == "&mut" {
return .object(.byMutableReference)
}

return .object(.byValue)
}
}

Loading
Loading