p

package module
v0.0.0-...-3b8683f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2022 License: Apache-2.0 Imports: 27 Imported by: 1

README

Google Cloud functions for BigTable

This is a reference implementaion for getting data out of BigTable.

Contents

This directory holds GCP Cloud Functions, one per file, along with shared utilities in shared.go. The file names correspond to the hosted endpoints. ie endpoint .../*-notionaltvl is the file notional-tvl.go

Debugging with VSCode

prereqs

  • Golang >= 1.16 installed and available on your path.
  • The Go VSCode extension, and gopls installed.

IDE setup

  • open a new VSCode window
  • File menu --> "Open Workspace from File..."
  • Select event_database/cloud_functions/workspace.code-workspace

Opening the workspace file as described above will open both cloud_functions and functions_server, so that you get all the VSCode goodness of intellesense, ability to run the code with the Go debugger, set breakpoints, etc.

Add your environment variables to functions_server/.vscode/launch.json

Start the debug server by pressing F5. You can check your server is up by requesting http://localhost:8080/readyz.

deploying

First deploy (creation) must include all the flags to configure the environment:

gcloud functions --project your-project deploy testnet --region europe-west3 --entry-point Entry --runtime go116 --trigger-http --allow-unauthenticated --service-account=your-readonly@your-project.iam.gserviceaccount.com --update-env-vars GCP_PROJECT=your-project,BIGTABLE_INSTANCE=wormhole-testnet

gcloud functions --project your-project deploy processvaa-testnet --region europe-west3 --entry-point ProcessVAA --runtime go116 --trigger-topic new-vaa-testnet --service-account=your-readonly@your-project.iam.gserviceaccount.com --update-env-vars GCP_PROJECT=your-project,BIGTABLE_INSTANCE=wormhole-testnet

Subsequent deploys (updates) only need include flags to indentify the resource for updating: project, region, name.

gcloud functions --project your-project deploy testnet --region europe-west3 --entry-point Entry

gcloud functions --project your-project deploy processvaa-testnet --region europe-west3 --entry-point ProcessVAA

invocation

All routes accept their input(s) as query parameters, or request body. Just two different ways of querying:

GET

curl "https://region-project-id.cloudfunctions.net/testnet/readrow?emitterChain=2&emitterAddress=000000000000000000000000e982e462b094850f12af94d21d470e21be9d0e9c&sequence=0000000000000006"

POST

curl -X POST  https://region-project-id.cloudfunctions.net/testnet/readrow \
-H "Content-Type:application/json" \
-d \
'{"emitterChain":"2", "emitterAddress":"000000000000000000000000e982e462b094850f12af94d21d470e21be9d0e9c", "sequence":"0000000000000006"}'

See ./bigtable-endpoints.md for API patterns

Documentation

Overview

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Package p contains an HTTP Cloud Function.

Index

Constants

View Source
const MAX_INT64 = 9223372036854775807

Variables

View Source
var NFTEmitters = map[string]string{}

NFTEmitters will be populated with lowercase addresses

View Source
var TokenTransferEmitters = map[string]string{}

TokenTransferEmitters will be populated with lowercase addresses

Functions

func AddressesTransferredTo

func AddressesTransferredTo(w http.ResponseWriter, r *http.Request)

find the addresses tokens have been transferred to

func AddressesTransferredToCumulative

func AddressesTransferredToCumulative(w http.ResponseWriter, r *http.Request)

finds unique addresses that tokens have been transferred to.

func ComputeNotionalTransferredFrom

func ComputeNotionalTransferredFrom(w http.ResponseWriter, r *http.Request)

finds the value that has been transferred from each chain

func ComputeTVL

func ComputeTVL(w http.ResponseWriter, r *http.Request)

calculates the value locked

func ComputeTransactionTotals

func ComputeTransactionTotals(w http.ResponseWriter, r *http.Request)

func ComputeTvlCumulative

func ComputeTvlCumulative(w http.ResponseWriter, r *http.Request)

calculates the cumulative value transferred each day since launch.

func FindValues

func FindValues(w http.ResponseWriter, r *http.Request)

fetch rows by matching payload value

func NFTs

func NFTs(w http.ResponseWriter, r *http.Request)

get number of recent transactions in the last 24 hours, and daily for a period optionally group by a EmitterChain or EmitterAddress optionally query for recent rows of a given EmitterChain or EmitterAddress

func NotionalTransferred

func NotionalTransferred(w http.ResponseWriter, r *http.Request)

finds the value that has been transferred from each chain to each other, by symbol.

func NotionalTransferredFrom

func NotionalTransferredFrom(w http.ResponseWriter, r *http.Request)

func NotionalTransferredTo

func NotionalTransferredTo(w http.ResponseWriter, r *http.Request)

finds the value that has been transferred to each chain, by symbol.

func NotionalTransferredToCumulative

func NotionalTransferredToCumulative(w http.ResponseWriter, r *http.Request)

calculates the cumulative value transferred each day since launch.

func ProcessTransfer

func ProcessTransfer(ctx context.Context, m PubSubMessage) error

ProcessTransfer is triggered by a PubSub message, once a TokenTransferPayload is written to a row.

func ProcessVAA

func ProcessVAA(ctx context.Context, m PubSubMessage) error

ProcessVAA is triggered by a PubSub message, emitted after row is saved to BigTable by guardiand

func ReadRow

func ReadRow(w http.ResponseWriter, r *http.Request)

fetch a single row by the row key

func Recent

func Recent(w http.ResponseWriter, r *http.Request)

fetch recent rows. optionally group by a EmitterChain or EmitterAddress optionally query for recent rows of a given EmitterChain or EmitterAddress

func TVL

func TVL(w http.ResponseWriter, r *http.Request)

func Totals

func Totals(w http.ResponseWriter, r *http.Request)

get number of recent transactions in the last 24 hours, and daily for a period optionally group by a EmitterChain or EmitterAddress optionally query for recent rows of a given EmitterChain or EmitterAddress

func Transaction

func Transaction(w http.ResponseWriter, r *http.Request)

fetch a single row by transaction identifier

func TransactionTotals

func TransactionTotals(w http.ResponseWriter, r *http.Request)

func TrimUnicodeFromByteArray

func TrimUnicodeFromByteArray(b []byte) []byte

func TvlCumulative

func TvlCumulative(w http.ResponseWriter, r *http.Request)

Types

type AddressData

type AddressData struct {
	TokenSymbol        string
	TokenAmount        float64
	OriginChain        string
	LeavingChain       string
	DestinationChain   string
	DestinationAddress string
	Notional           float64
}

type AssetMeta

type AssetMeta struct {
	PayloadId    uint8
	TokenAddress [32]byte
	TokenChain   uint16
	Decimals     uint8
	Symbol       [32]byte
	Name         [32]byte
}

func DecodeAssetMeta

func DecodeAssetMeta(data []byte) (*AssetMeta, error)

type AssetMetaPayload

type AssetMetaPayload struct {
	TokenAddress    string
	TokenChain      string
	Decimals        string
	Symbol          string
	Name            string
	CoinGeckoCoinId string
	NativeAddress   string
}

type ChainDetails

type ChainDetails struct {
	SenderAddress   string
	ReceiverAddress string
}

type CoinGeckoCoin

type CoinGeckoCoin struct {
	Id     string `json:"id"`
	Symbol string `json:"symbol"`
	Name   string `json:"name"`
}

type CoinGeckoCoinPrices

type CoinGeckoCoinPrices map[string]Price

type CoinGeckoCoins

type CoinGeckoCoins []CoinGeckoCoin

type CoinGeckoErrorRes

type CoinGeckoErrorRes struct {
	Error string `json:"error"`
}

type CoinGeckoMarket

type CoinGeckoMarket [2]float64

type CoinGeckoMarketRes

type CoinGeckoMarketRes struct {
	Prices []CoinGeckoMarket `json:"prices"`
}

type Details

type Details struct {
	Summary
	SignedVAA            *vaa.VAA
	TokenTransferPayload *TokenTransferPayload
	AssetMetaPayload     *AssetMetaPayload
	NFTTransferPayload   *NFTTransferPayload
	ChainDetails         *ChainDetails
}

Details is a Summary extended with all the post-processing ColumnFamilies

type LockedAsset

type LockedAsset struct {
	Symbol        string
	Name          string
	Address       string
	CoinGeckoId   string
	Amount        float64
	Notional      float64
	TokenPrice    float64
	TokenDecimals int
}

type NFTTransfer

type NFTTransfer struct {
	PayloadId     uint8
	OriginAddress [32]byte
	OriginChain   uint16
	Symbol        [32]byte
	Name          [32]byte
	TokenId       uint256.Int
	URI           []byte
	TargetAddress [32]byte
	TargetChain   uint16
}

func DecodeNFTTransfer

func DecodeNFTTransfer(data []byte) (*NFTTransfer, error)

type NFTTransferPayload

type NFTTransferPayload struct {
	OriginAddress string
	OriginChain   string
	Symbol        string
	Name          string
	TokenId       string
	URI           string
	TargetAddress string
	TargetChain   string
}

type Price

type Price struct {
	USD float64 `json:"usd"`
}

type PubSubMessage

type PubSubMessage struct {
	Data []byte `json:"data"`
}

type SolanaBeachAccountOwner

type SolanaBeachAccountOwner struct {
	Owner SolanaBeachAccountOwnerAddress `json:"owner"`
}

type SolanaBeachAccountOwnerAddress

type SolanaBeachAccountOwnerAddress struct {
	Address string `json:"address"`
}

type SolanaBeachAccountResponse

type SolanaBeachAccountResponse struct {
	Value struct {
		Extended struct {
			SolanaBeachAccountOwner
		} `json:"extended"`
	} `json:"value"`
}

type SolanaToken

type SolanaToken struct {
	Address  string `json:"address"`
	Symbol   string `json:"symbol"`
	Name     string `json:"name"`
	Decimals int    `json:"decimals"`
}

type SolanaTokenListRes

type SolanaTokenListRes struct {
	Tokens []SolanaToken `json:"tokens"`
}

type Summary

type Summary struct {
	EmitterChain    string
	EmitterAddress  string
	Sequence        string
	InitiatingTxID  string
	Payload         []byte
	SignedVAABytes  []byte
	QuorumTime      string
	TransferDetails *TransferDetails
}

Summary is MessagePublication data & QuorumState data

type TokenTransfer

type TokenTransfer struct {
	PayloadId     uint8
	Amount        uint256.Int
	OriginAddress [32]byte
	OriginChain   uint16
	TargetAddress [32]byte
	TargetChain   uint16
}

func DecodeTokenTransfer

func DecodeTokenTransfer(data []byte) (*TokenTransfer, error)

type TokenTransferPayload

type TokenTransferPayload struct {
	Amount        string
	OriginAddress string
	OriginChain   string
	TargetAddress string
	TargetChain   string
}

The following structs match the ColumnFamiles they are named after

type TransferData

type TransferData struct {
	TokenSymbol       string
	TokenName         string
	TokenAddress      string
	TokenAmount       float64
	CoinGeckoCoinId   string
	OriginChain       string
	LeavingChain      string
	DestinationChain  string
	Notional          float64
	TokenPrice        float64
	TokenDecimals     int
	TransferTimestamp string
}

type TransferDetails

type TransferDetails struct {
	Amount             string
	Decimals           string
	NotionalUSDStr     string
	TokenPriceUSDStr   string
	TransferTimestamp  string
	OriginSymbol       string
	OriginName         string
	OriginTokenAddress string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL