chore: release v0.4.1
This commit is contained in:
+115
@@ -0,0 +1,115 @@
|
||||
package rudder
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"hub.rudder.build/rudder/rudder-module-go/abi"
|
||||
)
|
||||
|
||||
type Ledger struct{}
|
||||
|
||||
func (Ledger) Balance(parameters abi.LedgerBalanceParameters) (*abi.LedgerBalanceResult, error) {
|
||||
return callResult[abi.LedgerBalanceResult](parameters)
|
||||
}
|
||||
|
||||
func (Ledger) Balances(parameters abi.LedgerBalancesParameters) (*abi.LedgerBalancesResult, error) {
|
||||
return callResult[abi.LedgerBalancesResult](parameters)
|
||||
}
|
||||
|
||||
func (Ledger) Credit(parameters abi.LedgerCreditParameters) (*abi.LedgerCreditResult, error) {
|
||||
return callResult[abi.LedgerCreditResult](parameters)
|
||||
}
|
||||
|
||||
func (Ledger) Debit(parameters abi.LedgerDebitParameters) (*abi.LedgerDebitResult, error) {
|
||||
return callResult[abi.LedgerDebitResult](parameters)
|
||||
}
|
||||
|
||||
func (Ledger) History(parameters abi.LedgerHistoryParameters) (*abi.LedgerHistoryResult, error) {
|
||||
return callResult[abi.LedgerHistoryResult](parameters)
|
||||
}
|
||||
|
||||
type Inventory struct{}
|
||||
|
||||
func (Inventory) Get(parameters abi.InventoryGetParameters) (*abi.InventoryGetResult, error) {
|
||||
return callResult[abi.InventoryGetResult](parameters)
|
||||
}
|
||||
|
||||
func (Inventory) List(parameters abi.InventoryListParameters) (*abi.InventoryListResult, error) {
|
||||
return callResult[abi.InventoryListResult](parameters)
|
||||
}
|
||||
|
||||
func (Inventory) Has(parameters abi.InventoryHasParameters) (*abi.InventoryHasResult, error) {
|
||||
return callResult[abi.InventoryHasResult](parameters)
|
||||
}
|
||||
|
||||
func (Inventory) Grant(parameters abi.InventoryGrantParameters) error {
|
||||
return call(parameters, nil)
|
||||
}
|
||||
|
||||
func (Inventory) Consume(parameters abi.InventoryConsumeParameters) error {
|
||||
return call(parameters, nil)
|
||||
}
|
||||
|
||||
type Storage struct{}
|
||||
|
||||
func (Storage) Get(parameters abi.StorageGetParameters) (*abi.StorageGetResult, error) {
|
||||
return callResult[abi.StorageGetResult](parameters)
|
||||
}
|
||||
|
||||
func (Storage) Set(parameters abi.StorageSetParameters) error {
|
||||
return call(parameters, nil)
|
||||
}
|
||||
|
||||
type ProjectStorage struct{}
|
||||
|
||||
func (ProjectStorage) Get(parameters abi.ProjectStorageGetParameters) (*abi.ProjectStorageGetResult, error) {
|
||||
return callResult[abi.ProjectStorageGetResult](parameters)
|
||||
}
|
||||
|
||||
func (ProjectStorage) Set(parameters abi.ProjectStorageSetParameters) error {
|
||||
return call(parameters, nil)
|
||||
}
|
||||
|
||||
type Segments struct{}
|
||||
|
||||
func (Segments) Match(parameters abi.SegmentsMatchParameters) (*abi.SegmentsMatchResult, error) {
|
||||
return callResult[abi.SegmentsMatchResult](parameters)
|
||||
}
|
||||
|
||||
func (Segments) Bucket(parameters abi.SegmentsBucketParameters) (*abi.SegmentsBucketResult, error) {
|
||||
return callResult[abi.SegmentsBucketResult](parameters)
|
||||
}
|
||||
|
||||
type Events struct{}
|
||||
|
||||
func (Events) Emit(parameters abi.EventsEmitParameters) error {
|
||||
return call(parameters, nil)
|
||||
}
|
||||
|
||||
type Data struct{}
|
||||
|
||||
func (Data) Exec(parameters abi.DataExecParameters) (*abi.DataExecResult, error) {
|
||||
return callResult[abi.DataExecResult](parameters)
|
||||
}
|
||||
|
||||
type Modules struct{}
|
||||
|
||||
func (Modules) Call(module string, function string, args any) (json.RawMessage, error) {
|
||||
body, err := json.Marshal(args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var result abi.ModulesCallResult
|
||||
if err := call(abi.ModulesCallParameters{Module: module, Function: function, Arguments: body}, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.Value, nil
|
||||
}
|
||||
|
||||
func callResult[Result any](parameters any) (*Result, error) {
|
||||
var result Result
|
||||
if err := call(parameters, &result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
Reference in New Issue
Block a user