Skip to content

Commit

Permalink
verified target is working
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhoonbang committed Oct 16, 2024
1 parent 9d2beb5 commit 0c6177a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
1 change: 1 addition & 0 deletions core/capabilities/webapi/target/connector_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func (c *ConnectorHandler) HandleSingleNodeRequest(ctx context.Context, messageI

select {
case resp := <-ch:
l.Debugw("received response from gateway")
return resp, nil
case <-ctx.Done():
return nil, ctx.Err()
Expand Down
35 changes: 21 additions & 14 deletions core/scripts/gateway/web_api_trigger/invoke_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"io"
"net/http"
"os"
"strconv"
"time"

"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -77,30 +76,38 @@ func main() {
return
}

payload := `{
"trigger_id": "web-api-trigger@1.0.0",
"trigger_event_id": "action_1234567890",
"timestamp": ` + strconv.Itoa(int(time.Now().Unix())) + `,
"topics": ["daily_price_update"],
"params": {
"bid": "101",
"ask": "102"
}
}
`
payloadJSON := []byte(payload)
address := crypto.PubkeyToAddress(key.PublicKey)
fmt.Printf("Public Address: %s\n", address.Hex())

payload := map[string]any{
"trigger_id": "web-api-trigger@1.0.0",
"trigger_event_id": "action_1234567890",
"timestamp": int(time.Now().Unix()),
"topics": []string{"daily_price_update"},
"params": map[string]string{
"bid": "101",
"ask": "102",
},
}

payloadJSON, err := json.Marshal(payload)
if err != nil {
fmt.Println("error marshalling JSON payload", err)
return
}
msg := &api.Message{
Body: api.MessageBody{
MessageId: *messageID,
Method: *methodName,
DonId: *donID,
Payload: json.RawMessage(payloadJSON),
Payload: payloadJSON,
},
}
if err = msg.Sign(key); err != nil {
fmt.Println("error signing message", err)
return
}

codec := api.JsonRPCCodec{}
rawMsg, err := codec.EncodeRequest(msg)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions core/services/gateway/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/jonboulle/clockwork"

"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/utils/hex"
commonhex "github.com/smartcontractkit/chainlink-common/pkg/utils/hex"

"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/gateway/api"
Expand Down Expand Up @@ -91,7 +91,7 @@ func NewGatewayConnector(config *ConnectorConfig, signer Signer, clock clockwork
if len(config.DonId) == 0 || len(config.DonId) > network.HandshakeDonIdLen {
return nil, errors.New("invalid DON ID")
}
addressBytes, err := hex.DecodeString(config.NodeAddress)
addressBytes, err := commonhex.DecodeString(config.NodeAddress)
if err != nil {
return nil, err
}
Expand Down
8 changes: 5 additions & 3 deletions core/services/gateway/handlers/webapicapabilities/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,18 @@ func (h *handler) handleWebAPITargetMessage(ctx context.Context, msg *api.Messag
DonId: msg.Body.DonId,
Payload: payloadBytes,
},
// this signature is not verified by the node because
// WS connection between gateway and node are already verified
Signature: msg.Signature,
}
}
// this signature is not verified by the node because
// WS connection between gateway and node are already verified
respMsg.Signature = msg.Signature

err = h.don.SendToNode(newCtx, nodeAddr, respMsg)
if err != nil {
l.Errorw("failed to send to node", "err", err, "to", nodeAddr)
return
}
l.Debugw("sent response to node", "to", nodeAddr)
}()
return nil
}
Expand Down

0 comments on commit 0c6177a

Please sign in to comment.