This repository was archived by the owner on Jul 10, 2020. It is now read-only.
Description Example Cosmos RPC: https://github.com/trustwallet/web-core/tree/master/packages/rpc/src/cosmos
Endpoint: for testing: https://vethor-node.vechain.com
Replicate Swift implementation in TypeScript, as implemented in Vechain RPC
Swift implementation:
enum VechainRPC {
case getBalance( address: String )
case sendTransaction( VechainSendTransaction )
case getTransactionReceipt( id: String )
case getBlock
case callContract( contract: String , VechainCallContract )
}
extension VechainRPC : TargetType {
var baseURL : URL {
return RPCServer ( . vechain) . rpcURL
}
var path : String {
switch self {
case . getBalance( let address) :
return " /accounts/ \( address) "
case . sendTransaction:
return " /transactions "
case . getTransactionReceipt( let id) :
return " /transactions/ " + id + " /receipt "
case . getBlock:
return " /blocks/best "
case . callContract( let contract, _) :
return " /accounts/ \( contract) "
}
}
var method : Moya . Method {
switch self {
case . getBalance: return . get
case . sendTransaction: return . post
case . getTransactionReceipt: return . get
case . getBlock: return . get
case . callContract: return . post
}
}
var task : Task {
switch self {
case . getBalance, . getTransactionReceipt, . getBlock:
return . requestPlain
case . sendTransaction( let transaction) :
return . requestJSONEncodable( transaction)
case . callContract( _, let data) :
return . requestJSONEncodable( data)
}
}
var sampleData : Data {
return Data ( )
}
var headers : [ String : String ] ? {
return [
" Content-type " : " application/json " ,
]
}
}
Models:
struct VechainBalance : Codable {
let balance : String
let energy : String
}
struct VechainSendTransaction : Codable {
let raw : String
}
struct VechainSentTransaction : Codable {
let id : String
}
struct VechainTransactionReceipt : Codable {
let gasUsed : Int64
let reverted : Bool
}
struct VechainBlock : Codable {
let number : UInt64
let id : String
}
struct VechainCallContract : Codable {
let value : String
let data : String
}
struct VechainCallContractResponse : Codable {
let data : String
let gasUsed : UInt64
} Reactions are currently unavailable
Example Cosmos RPC: https://github.com/trustwallet/web-core/tree/master/packages/rpc/src/cosmos
Endpoint: for testing:
https://vethor-node.vechain.comReplicate Swift implementation in TypeScript, as implemented in Vechain RPC
Swift implementation:
Models: