mirror of
https://github.com/callebtc/electronwall.git
synced 2025-12-17 07:04:21 +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) {
|
||||
|
||||
url := "https://api.amboss.space/graphql"
|
||||
log.Infof("Getting info from amboss.space for %s", pubkey)
|
||||
|
||||
graphqlClient := graphql.NewClient(url)
|
||||
graphqlRequest := graphql.NewRequest(simple_query)
|
||||
graphqlRequest := graphql.NewRequest(amboss_graphql_query)
|
||||
graphqlRequest.Var("pubkey", pubkey)
|
||||
// set header fields
|
||||
graphqlRequest.Header.Set("Cache-Control", "no-cache")
|
||||
graphqlRequest.Header.Set("Content-Type", "application/json")
|
||||
|
||||
var r_nested *AutoGenerated
|
||||
if err := graphqlClient.Run(context.Background(), graphqlRequest, &r_nested); err != nil {
|
||||
var r_nested Amboss_NodeInfoResponse_Nested
|
||||
if err := graphqlClient.Run(context.Background(), graphqlRequest, &r_nested.Data); err != nil {
|
||||
log.Errorf("[amboss] api error: %v", err)
|
||||
}
|
||||
|
||||
// r := r_nested.Data.GetNode.Amboss_NodeInfoResponse
|
||||
|
||||
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
|
||||
r := r_nested.Data.GetNode.Amboss_NodeInfoResponse
|
||||
return r, nil
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ type ApiClient interface {
|
||||
}
|
||||
|
||||
type ApiNodeInfo struct {
|
||||
OneMl OneML_NodeInfoResponse
|
||||
Amboss Amboss_NodeInfoResponse
|
||||
OneMl OneML_NodeInfoResponse `json:"1ml"`
|
||||
Amboss Amboss_NodeInfoResponse `json:"amboss"`
|
||||
}
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
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
|
||||
alias, err := app.lnd.getNodeAlias(ctx, hex.EncodeToString(req.NodePubkey))
|
||||
if err != nil {
|
||||
@@ -77,7 +77,7 @@ func (app *App) interceptChannelEvents(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
channelAcceptEvent, err := app.getChannelAcceptEvent(ctx, req)
|
||||
channelAcceptEvent, err := app.GetChannelAcceptEvent(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
if (
|
||||
ChannelAccept.Event.FundingAmt >= 750000 &&
|
||||
ChannelAccept.OneMl.LastUpdate > 1661227900 &&
|
||||
ChannelAccept.OneMl.Noderank.Availability > 100 &&
|
||||
ChannelAccept.Amboss.Socials.Info.Email
|
||||
// (
|
||||
// ChannelAccept.Amboss.Socials.Info.Email.length > 0 ||
|
||||
// ChannelAccept.Amboss.Socials.Info.Twitter.length >0 ||
|
||||
// ChannelAccept.Amboss.Socials.Info.Telegram.length >0
|
||||
// )
|
||||
// ChannelAccept.Amboss.Amboss.IsPrime == false
|
||||
) { true } else { false }
|
||||
// only channels > 0.75 Msat
|
||||
ChannelAccept.Event.FundingAmt >= 750000 &&
|
||||
// nodes with high 1ML availability score
|
||||
ChannelAccept.OneMl.Noderank.Availability > 100 &&
|
||||
// nodes with a low enough 1ML age rank
|
||||
ChannelAccept.OneMl.Noderank.Age < 10000 &&
|
||||
(
|
||||
// only nodes with Amboss contact data
|
||||
ChannelAccept.Amboss.Socials.Info.Email ||
|
||||
ChannelAccept.Amboss.Socials.Info.Twitter ||
|
||||
ChannelAccept.Amboss.Socials.Info.Telegram
|
||||
) &&
|
||||
(
|
||||
// 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 {
|
||||
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:
|
||||
return false, fmt.Errorf("no rule found for event type")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user