github.com/diadata-org/diadata@v1.4.593/pkg/dia/helpers/substrate-helper/gsrpc/rpc/main.go (about)

     1  // Go Substrate RPC Client (GSRPC) provides APIs and types around Polkadot and any Substrate-based chain RPC calls
     2  //
     3  // Copyright 2019 Centrifuge GmbH
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  package rpc
    18  
    19  import (
    20  	"github.com/diadata-org/diadata/pkg/dia/helpers/substrate-helper/gsrpc/client"
    21  	"github.com/diadata-org/diadata/pkg/dia/helpers/substrate-helper/gsrpc/rpc/author"
    22  	"github.com/diadata-org/diadata/pkg/dia/helpers/substrate-helper/gsrpc/rpc/beefy"
    23  	"github.com/diadata-org/diadata/pkg/dia/helpers/substrate-helper/gsrpc/rpc/chain"
    24  	"github.com/diadata-org/diadata/pkg/dia/helpers/substrate-helper/gsrpc/rpc/offchain"
    25  	"github.com/diadata-org/diadata/pkg/dia/helpers/substrate-helper/gsrpc/rpc/state"
    26  	"github.com/diadata-org/diadata/pkg/dia/helpers/substrate-helper/gsrpc/rpc/system"
    27  	"github.com/diadata-org/diadata/pkg/dia/helpers/substrate-helper/gsrpc/types"
    28  )
    29  
    30  type RPC struct {
    31  	Author   author.Author
    32  	Beefy    beefy.Beefy
    33  	Chain    chain.Chain
    34  	Offchain offchain.Offchain
    35  	State    state.State
    36  	System   system.System
    37  	client   client.Client
    38  }
    39  
    40  func NewRPC(cl client.Client) (*RPC, error) {
    41  	st := state.NewState(cl)
    42  	meta, err := st.GetMetadataLatest()
    43  	if err != nil {
    44  		return nil, err
    45  	}
    46  
    47  	opts := types.SerDeOptionsFromMetadata(meta)
    48  	types.SetSerDeOptions(opts)
    49  
    50  	return &RPC{
    51  		Author:   author.NewAuthor(cl),
    52  		Beefy:    beefy.NewBeefy(cl),
    53  		Chain:    chain.NewChain(cl),
    54  		Offchain: offchain.NewOffchain(cl),
    55  		State:    st,
    56  		System:   system.NewSystem(cl),
    57  		client:   cl,
    58  	}, nil
    59  }