mirror of
https://github.com/callebtc/electronwall.git
synced 2025-12-17 15:14:25 +01:00
api done
This commit is contained in:
@@ -167,58 +167,21 @@ func GetAmbossClient() AmbossClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *AmbossClient) GetNodeInfo(pubkey string) (Amboss_NodeInfoResponse, error) {
|
func (c *AmbossClient) GetNodeInfo(pubkey string) (Amboss_NodeInfoResponse, error) {
|
||||||
|
|
||||||
url := "https://api.amboss.space/graphql"
|
url := "https://api.amboss.space/graphql"
|
||||||
log.Infof("Getting info from amboss.space for %s", pubkey)
|
log.Infof("Getting info from amboss.space for %s", pubkey)
|
||||||
|
|
||||||
graphqlClient := graphql.NewClient(url)
|
graphqlClient := graphql.NewClient(url)
|
||||||
graphqlRequest := graphql.NewRequest(simple_query)
|
graphqlRequest := graphql.NewRequest(amboss_graphql_query)
|
||||||
graphqlRequest.Var("pubkey", pubkey)
|
graphqlRequest.Var("pubkey", pubkey)
|
||||||
// set header fields
|
// set header fields
|
||||||
graphqlRequest.Header.Set("Cache-Control", "no-cache")
|
graphqlRequest.Header.Set("Cache-Control", "no-cache")
|
||||||
graphqlRequest.Header.Set("Content-Type", "application/json")
|
graphqlRequest.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
var r_nested *AutoGenerated
|
var r_nested Amboss_NodeInfoResponse_Nested
|
||||||
if err := graphqlClient.Run(context.Background(), graphqlRequest, &r_nested); err != nil {
|
if err := graphqlClient.Run(context.Background(), graphqlRequest, &r_nested.Data); err != nil {
|
||||||
log.Errorf("[amboss] api error: %v", err)
|
log.Errorf("[amboss] api error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// r := r_nested.Data.GetNode.Amboss_NodeInfoResponse
|
r := r_nested.Data.GetNode.Amboss_NodeInfoResponse
|
||||||
|
return r, nil
|
||||||
return Amboss_NodeInfoResponse{}, nil
|
|
||||||
// jsonData := map[string]string{
|
|
||||||
// "query": query,
|
|
||||||
// "variables": variables,
|
|
||||||
// }
|
|
||||||
|
|
||||||
// client := http.Client{
|
|
||||||
// Timeout: time.Second * 2, // Timeout after 2 seconds
|
|
||||||
// }
|
|
||||||
|
|
||||||
// req, err := http.NewRequest(http.MethodGet, url, nil)
|
|
||||||
// if err != nil {
|
|
||||||
// log.Fatal(err)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// res, getErr := client.Do(req)
|
|
||||||
// if getErr != nil {
|
|
||||||
// log.Fatal(getErr)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if res.Body != nil {
|
|
||||||
// defer res.Body.Close()
|
|
||||||
// }
|
|
||||||
|
|
||||||
// body, readErr := ioutil.ReadAll(res.Body)
|
|
||||||
// if readErr != nil {
|
|
||||||
// log.Fatal(readErr)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// r := Amboss_NodeInfoResponse{}
|
|
||||||
// jsonErr := json.Unmarshal(body, &r)
|
|
||||||
// if jsonErr != nil {
|
|
||||||
// log.Errorf("API error: %v", jsonErr)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return r, nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ type ApiClient interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ApiNodeInfo struct {
|
type ApiNodeInfo struct {
|
||||||
OneMl OneML_NodeInfoResponse
|
OneMl OneML_NodeInfoResponse `json:"1ml"`
|
||||||
Amboss Amboss_NodeInfoResponse
|
Amboss Amboss_NodeInfoResponse `json:"amboss"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetApiNodeinfo(pubkey string) (ApiNodeInfo, error) {
|
func GetApiNodeinfo(pubkey string) (ApiNodeInfo, error) {
|
||||||
|
|||||||
51
api_test/main.go
Normal file
51
api_test/main.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/callebtc/electronwall/api"
|
||||||
|
"github.com/callebtc/electronwall/rules"
|
||||||
|
"github.com/callebtc/electronwall/types"
|
||||||
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
if len(os.Args) < 2 {
|
||||||
|
log.Errorf("Pass node ID as argument.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pubkey := os.Args[1]
|
||||||
|
log.Infof("pubkey: %s", pubkey)
|
||||||
|
pk_byte := []byte(pubkey)
|
||||||
|
decision_chan := make(chan bool, 1)
|
||||||
|
event := types.ChannelAcceptEvent{}
|
||||||
|
|
||||||
|
event.Event = &lnrpc.ChannelAcceptRequest{}
|
||||||
|
|
||||||
|
event.Event.FundingAmt = 1_000_000
|
||||||
|
log.Infof("Funding amount: %d sat", event.Event.FundingAmt)
|
||||||
|
event.Event.NodePubkey = pk_byte
|
||||||
|
|
||||||
|
req := lnrpc.ChannelAcceptRequest{}
|
||||||
|
req.NodePubkey = pk_byte
|
||||||
|
|
||||||
|
nodeInfo, err := api.GetApiNodeinfo(string(req.NodePubkey))
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf(err.Error())
|
||||||
|
}
|
||||||
|
// log.Infoln("1ML")
|
||||||
|
// // log.Infoln("%+v", noeInfo.OneMl)
|
||||||
|
// log.Printf("%+v\n", nodeInfo.OneMl)
|
||||||
|
// log.Infoln("Amboss")
|
||||||
|
// log.Printf("%+v\n", nodeInfo.Amboss)
|
||||||
|
|
||||||
|
event.OneMl = nodeInfo.OneMl
|
||||||
|
event.Amboss = nodeInfo.Amboss
|
||||||
|
|
||||||
|
rules_decision, err := rules.Apply(event, decision_chan)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
log.Infof("Decision: %t", rules_decision)
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (app *App) getChannelAcceptEvent(ctx context.Context, req lnrpc.ChannelAcceptRequest) (types.ChannelAcceptEvent, error) {
|
func (app *App) GetChannelAcceptEvent(ctx context.Context, req lnrpc.ChannelAcceptRequest) (types.ChannelAcceptEvent, error) {
|
||||||
// print the incoming channel request
|
// print the incoming channel request
|
||||||
alias, err := app.lnd.getNodeAlias(ctx, hex.EncodeToString(req.NodePubkey))
|
alias, err := app.lnd.getNodeAlias(ctx, hex.EncodeToString(req.NodePubkey))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -77,7 +77,7 @@ func (app *App) interceptChannelEvents(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
channelAcceptEvent, err := app.getChannelAcceptEvent(ctx, req)
|
channelAcceptEvent, err := app.GetChannelAcceptEvent(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
if (
|
// only channels > 0.75 Msat
|
||||||
ChannelAccept.Event.FundingAmt >= 750000 &&
|
ChannelAccept.Event.FundingAmt >= 750000 &&
|
||||||
ChannelAccept.OneMl.LastUpdate > 1661227900 &&
|
// nodes with high 1ML availability score
|
||||||
ChannelAccept.OneMl.Noderank.Availability > 100 &&
|
ChannelAccept.OneMl.Noderank.Availability > 100 &&
|
||||||
ChannelAccept.Amboss.Socials.Info.Email
|
// nodes with a low enough 1ML age rank
|
||||||
// (
|
ChannelAccept.OneMl.Noderank.Age < 10000 &&
|
||||||
// ChannelAccept.Amboss.Socials.Info.Email.length > 0 ||
|
(
|
||||||
// ChannelAccept.Amboss.Socials.Info.Twitter.length >0 ||
|
// only nodes with Amboss contact data
|
||||||
// ChannelAccept.Amboss.Socials.Info.Telegram.length >0
|
ChannelAccept.Amboss.Socials.Info.Email ||
|
||||||
// )
|
ChannelAccept.Amboss.Socials.Info.Twitter ||
|
||||||
// ChannelAccept.Amboss.Amboss.IsPrime == false
|
ChannelAccept.Amboss.Socials.Info.Telegram
|
||||||
) { true } else { false }
|
) &&
|
||||||
|
(
|
||||||
|
// elitist: either nodes with amboss prime
|
||||||
|
ChannelAccept.Amboss.Amboss.IsPrime ||
|
||||||
|
// or nodes with high-ranking capacity
|
||||||
|
ChannelAccept.Amboss.GraphInfo.Metrics.CapacityRank < 1000 ||
|
||||||
|
// or nodes with high-ranking channel count
|
||||||
|
ChannelAccept.Amboss.GraphInfo.Metrics.ChannelsRank < 1000
|
||||||
|
)
|
||||||
|
|||||||
@@ -28,12 +28,6 @@ func Apply(s interface{}, decision_chan chan bool) (accept bool, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
// case *routerrpc.ForwardHtlcInterceptRequest:
|
|
||||||
// vm.Set("HtlcForwardEvent", s)
|
|
||||||
// js_script, err = os.ReadFile("rules/ForwardHtlcInterceptRequest.js")
|
|
||||||
// if err != nil {
|
|
||||||
// log.Fatal(err)
|
|
||||||
// }
|
|
||||||
default:
|
default:
|
||||||
return false, fmt.Errorf("no rule found for event type")
|
return false, fmt.Errorf("no rule found for event type")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user