Skip to content

Commit

Permalink
fix missing zos calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Chaddad committed Aug 27, 2023
1 parent bb430a2 commit 54b9dad
Show file tree
Hide file tree
Showing 13 changed files with 495 additions and 168 deletions.
147 changes: 147 additions & 0 deletions web3gw/client/tfchain/model.v
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,150 @@ pub:
timeout int // the timeout after which we abandon the search
height int // at what blockheight to start looking for the transaction
}

pub struct TwinOptionRelay {
pub:
has_value bool
as_value string
}

pub struct TwinEntityProof {
pub:
entity_id u32
signature string

}

pub struct TwinData {
pub:
id u32
account_id string
relay TwinOptionRelay
entities []TwinEntityProof

}

pub struct NodeResources {
pub:
hru u64
sru u64
cru u64
mru u64
}

pub struct NodeLocation {
pub:
city string
country string
latitude string
longitude string
}

pub struct NodeIP {
pub:
ip string
gw string
}

pub struct NodeOptionIP {
pub:
has_value bool
as_value NodeIP
}

pub struct NodeOptionDomain {
pub:
has_value bool
as_value string
}

pub struct NodePublicConfig {
pub:
ip4 NodeIP
ip6 NodeOptionIP
domain NodeOptionDomain
}

pub struct NodeOptionPublicConfig {
pub:
has_value bool
as_value NodePublicConfig
}

pub struct NodeOptionBoardSerial {
pub:
has_value bool
as_value string
}

pub struct NodeCertification {
pub:
is_diy bool
is_certified bool
}

pub struct NodeData {
pub:
version u32
id u32
farm_id u32
twin_id u32
resources NodeResources
location NodeLocation
public_config NodeOptionPublicConfig
created u64
farming_policy u32
secure_boot bool
virtualized bool
board_serial NodeOptionBoardSerial
connection_price u32
}

pub struct ContractDeletedState {
pub:
is_canceled_by_user bool
is_out_of_funds bool
}

pub struct ContractState {
pub:
is_created bool
is_deleted bool
is_grace_period bool
as_grace_period_block_number u64
as_deleted ContractDeletedState
}


pub struct ContractData {
pub:
version u32
contract_id u64
twin_id u32
solution_provider_id u64
}

pub struct FarmCertification {
pub:
is_not_certified bool
is_gold bool
}

pub struct FarmPublicIP {
pub:
ip string
gateway string
contract_id u64
}

pub struct FarmData {
pub:
version u32
id u32
name string
twin_id u32
pricing_policy_id u32
certification_type FarmCertification
public_ips []FarmPublicIP
dedicated_farm bool
}
36 changes: 36 additions & 0 deletions web3gw/client/tfchain/tfchain.v
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,39 @@ pub fn (mut t TfChainClient) get_twin_by_pubkey(address string) !u32 {
return t.client.send_json_rpc[[]string, u32]('tfchain.GetTwinByPubKey', [address],
tfchain.default_timeout)!
}

// returns twin info via id
pub fn (mut t TfChainClient) get_twin(id u32) !TwinData {
return t.client.send_json_rpc[[]u32, TwinData]('tfchain.GetTwin', [id],
tfchain.default_timeout)!
}

pub fn (mut t TfChainClient) get_node(id u32) !NodeData {
return t.client.send_json_rpc[[]u32, NodeData]('tfchain.GetNode', [id],
tfchain.default_timeout)!
}

pub fn (mut t TfChainClient) get_nodes(farm_id u32) ![]u32 {
return t.client.send_json_rpc[[]u32, []u32]('tfchain.GetNodes', [farm_id],
tfchain.default_timeout)!
}

pub fn (mut t TfChainClient) get_node_contracts(id u32) ![]u64 {
return t.client.send_json_rpc[[]u32, []u64]('tfchain.GetNodeContracts', [id],
tfchain.default_timeout)!
}

pub fn (mut t TfChainClient) get_contract(id u64) !ContractData {
return t.client.send_json_rpc[[]u64, ContractData]('tfchain.GetContract', [id],
tfchain.default_timeout)!
}

pub fn (mut t TfChainClient) get_farm(id u32) !FarmData {
return t.client.send_json_rpc[[]u32, FarmData]('tfchain.GetFarm', [id],
tfchain.default_timeout)!
}

pub fn (mut t TfChainClient) get_farm_by_name(name string) !u32 {
return t.client.send_json_rpc[[]string, u32]('tfchain.GetFarmByName', [name],
tfchain.default_timeout)!
}
101 changes: 101 additions & 0 deletions web3gw/client/tfgrid/model.v
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,104 @@ pub:
ipv6 string // instance ipv6, if any
fqdn string // fully qualified domain name pointing to the instance
}

pub struct ZOSNodeRequest {
pub:
node_id int
data u64
}

pub struct NodeStatistics {
pub:
total Capacity
used Capacity
}

pub struct SystemTooling {
pub:
aggregator string
decoder string
}

pub struct SystemPropertyData {
pub:
value string
items []string
}

pub struct SystemSubsection {
pub:
title string
properties map[string]SystemPropertyData
}

pub struct SystemSection {
pub:
handleline string
typestr string
section_type int [json: 'type']
subsections []SystemSubsection
}

pub struct SystemDMI {
pub:
tooling SystemTooling
sections []SystemSection
}

pub struct ZOSVersion {
pub:
zos string
zinit string
}

pub struct WorkloadResult {
pub:
created u32
state string
message string
data u64
}

pub struct Workload {
pub:
version u32
name string
workload_type string [json: 'type']
data ZDBWorkload
metadata string
description string
result WorkloadResult
}

pub struct SignatureRequest {
twin_id u32
required bool
weight u32
}

pub struct SignatureRequirement {
pub:
weight_required int
requests []SignatureRequest
}

pub struct Deployment {
pub:
version u32
twin_id u32
contract_id u64
metadata string
description string
expiration u64
signature_requirement SignatureRequirement
workloads []Workload
}

pub struct ZDBWorkload {
pub:
password string
mode string
size u32
public bool
}
76 changes: 76 additions & 0 deletions web3gw/client/tfgrid/zos_calls.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
module tfgrid

import freeflowuniverse.crystallib.rpcwebsocket { RpcWsClient }


pub fn (mut t TFGridClient) zos_node_statistics(request ZOSNodeRequest) !NodeStatistics {
return t.client.send_json_rpc[[]ZOSNodeRequest, NodeStatistics]('tfgrid.ZOSStatisticsGet', [
request,
], t.timeout)!
}

pub fn (mut t TFGridClient) zos_network_list_wg_ports(request ZOSNodeRequest) ![]u16 {
return t.client.send_json_rpc[[]ZOSNodeRequest, []u16]('tfgrid.ZOSNetworkListWGPorts', [
request,
], t.timeout)!
}

pub fn (mut t TFGridClient) zos_network_interfaces(request ZOSNodeRequest) !map[string][]u32 {
return t.client.send_json_rpc[[]ZOSNodeRequest, map[string][]u32]('tfgrid.ZOSNetworkInterfaces', [
request,
], t.timeout)!
}

pub fn (mut t TFGridClient) zos_network_public_config(request ZOSNodeRequest) !PublicConfig {
return t.client.send_json_rpc[[]ZOSNodeRequest, PublicConfig]('tfgrid.ZOSNetworkPublicConfigGet', [
request,
], t.timeout)!
}

pub fn (mut t TFGridClient) zos_system_dmi(request ZOSNodeRequest) !SystemDMI {
return t.client.send_json_rpc[[]ZOSNodeRequest, SystemDMI]('tfgrid.ZOSSystemDMI', [
request,
], t.timeout)!
}

pub fn (mut t TFGridClient) zos_system_hypervisor(request ZOSNodeRequest) !string {
return t.client.send_json_rpc[[]ZOSNodeRequest, string]('tfgrid.ZOSSystemHypervisor', [
request,
], t.timeout)!
}

pub fn (mut t TFGridClient) zos_system_version(request ZOSNodeRequest) !ZOSVersion {
return t.client.send_json_rpc[[]ZOSNodeRequest, ZOSVersion]('tfgrid.ZOSSystemVersion', [
request,
], t.timeout)!
}

pub fn (mut t TFGridClient) zos_deployment_deploy(request ZOSNodeRequest) ! {
t.client.send_json_rpc[[]ZOSNodeRequest, string]('tfgrid.ZOSDeploymentDeploy', [
request,
], t.timeout)!
}

pub fn (mut t TFGridClient) zos_deployment_update(request ZOSNodeRequest) ! {
t.client.send_json_rpc[[]ZOSNodeRequest, string]('tfgrid.ZOSDeploymentUpdate', [
request,
], t.timeout)!
}

pub fn (mut t TFGridClient) zos_deployment_changes(request ZOSNodeRequest) !Workload {
return t.client.send_json_rpc[[]ZOSNodeRequest, Workload]('tfgrid.ZOSDeploymentChanges', [
request,
], t.timeout)!
}

pub fn (mut t TFGridClient) zos_deployment_get(request ZOSNodeRequest) !Deployment {
return t.client.send_json_rpc[[]ZOSNodeRequest, Deployment]('tfgrid.ZOSDeploymentGet', [
request,
], t.timeout)!
}

pub fn (mut t TFGridClient) zos_deployment_delete(request ZOSNodeRequest) ! {
t.client.send_json_rpc[[]ZOSNodeRequest, string]('tfgrid.ZOSDeploymentDelete', [
request,
], t.timeout)!
}
2 changes: 1 addition & 1 deletion web3gw/examples/nostr/chat_consumer.v
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn subscribe_messages(mut client RpcWsClient, mut logger log.Logger, secret stri
logger.info('Nostr: Public Key: ${public_key}')

nostr_client.connect_to_relay('https://nostr01.grid.tf/')!
nostr_client.subscribe_to_direct_messages()!
nostr_client.subscribe_direct_messages()!

for {
time.sleep(5 * time.second)
Expand Down
4 changes: 2 additions & 2 deletions web3gw/examples/nostr/stalls.v
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fn create_stall_and_product(mut client RpcWsClient, mut logger log.Logger, secre

nostr_client.connect_to_relay('https://nostr01.grid.tf/')!

nostr_client.subscribe_to_stall_creation()!
nostr_client.subscribe_to_product_creation()!
nostr_client.subscribe_stall_creation()!
nostr_client.subscribe_product_creation()!

stall := nostr.Stall{
id: 'stall1'
Expand Down
Loading

0 comments on commit 54b9dad

Please sign in to comment.