livequery-base/macros/livequery/utils.sql
Austin 040b3fdf9a
Stream 318/an 3432/stream 324/evm highl level abstractions (#24)
* - create place holder configs for high level evm abstractions

* - rename udf_config

* - fixed macro bug

* - add generic rpc_call

* - add generic evm rpc udf

* - add generic evm rpc udf

* - more DRY primitives

* WIP

* - add example udft

* - readme.MD

* - updated comments on evm primitives

* - add model to store signatures for UI

* evm abstractions

* use schema

* Squashed commit of the following:

commit df57d3309394d13407d5f4f7a1c27ab4e51ccb4e
Author: Julius Remigio <14811322+juls858@users.noreply.github.com>
Date:   Thu Jun 15 12:31:00 2023 -0700

     - remove unneeded model

* - refactor pimitives to use schema with network name

* schema fix and polygon

* - added udf_rpc to live schema
- prefixed primitives with udf_

* use crosschain table

* use sources for crosschain

* support all chains

* add network

* updated comments

* all chains

* remove map

* reorg

* remove optimism from map

* Update utils.sql

Return null instead of empty json object

* add error column

* Revert "add error column"

This reverts commit 49bc7239a43afaa9974abc2ab9408310c0757aa1.

* Revert "Update utils.sql"

This reverts commit 1edbeef5eebea6a5bffe3fc599afd2289864b359.

* Update utils.sql

Return null instead of empty json object

* Revert "Update utils.sql"

This reverts commit e4c29b093235cf9a36ca34e1000d1ad1c1a7beb6.

---------

Co-authored-by: Julius Remigio <14811322+juls858@users.noreply.github.com>
2023-06-27 11:55:30 -07:00

24 lines
860 B
SQL

{% macro sql_live_rpc_call(method, params, blockchain, network) %}
{#
Helper macro to call a JSON RPC method on a live node.
Parameters:
method (string): The JSON RPC method to call.
params (string): The JSON RPC parameters to pass to the method.
blockchain (string): The blockchain to call the method on.
network (string): The network to call the method on.
Returns:
string: The SQL to call the method.
#}
WITH result as (
SELECT
live.udf_api(
'{endpoint}'
,utils.udf_json_rpc_call({{ method }}, {{ params }})
,concat_ws('/', 'integration', _utils.udf_provider(), {{ blockchain }}, {{ network }})
)::VARIANT:data AS data
)
SELECT
COALESCE(data:result, {'error':data:error})
FROM result
{% endmacro -%}