From 8e77151c4d410d1303380838686dec134c8c2c0f Mon Sep 17 00:00:00 2001 From: Tanut Lertwarachai Date: Wed, 8 Apr 2026 15:09:12 +0700 Subject: [PATCH] add contract address field --- proto/fkms/v1/signer.proto | 2 +- src/codec/flow.rs | 26 ++++++++++++++++++++++++++ src/server/service.rs | 3 ++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/proto/fkms/v1/signer.proto b/proto/fkms/v1/signer.proto index 9897ef2..ce3bd73 100644 --- a/proto/fkms/v1/signer.proto +++ b/proto/fkms/v1/signer.proto @@ -83,7 +83,7 @@ message FlowSignerPayload { string block_id = 3; uint32 key_index = 4; uint64 sequence = 5; - bytes script = 6; + string contract_address = 6; } message SorobanSignerPayload { diff --git a/src/codec/flow.rs b/src/codec/flow.rs index 630863f..55c43cb 100644 --- a/src/codec/flow.rs +++ b/src/codec/flow.rs @@ -7,6 +7,32 @@ use sha3::{Digest, Sha3_256}; const FLOW_TRANSACTION_DOMAIN_TAG: &[u8] = b"FLOW-V0.0-transaction\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; +const RELAY_SCRIPT_TEMPLATE: &str = r#" + import BandOracle from {contract} + + transaction (symbolsRates: {String: UInt64}, resolveTime: UInt64, requestID: UInt64) { + let relayRef: &BandOracle.Relay + + prepare (acct: auth(BorrowValue)&Account){ + // Get a reference to the relayer resource from storage + self.relayRef = acct.storage.borrow<&BandOracle.Relay>(from: BandOracle.RelayStoragePath) ?? + panic("Cannot borrow reference to relay resource") + } + + execute { + // Call the relayRates function exposed by the relayer resource + self.relayRef.relayRates(symbolsRates: symbolsRates, resolveTime: resolveTime, requestID: requestID) + } + } +"#; + +/// Builds the Cadence relay script with the given contract address substituted in. +pub fn build_script(contract_address: &str) -> Vec { + RELAY_SCRIPT_TEMPLATE + .replace("{contract}", contract_address) + .into_bytes() +} + // Builds the RLP-encoded transaction payload used for signing. #[allow(clippy::too_many_arguments)] pub fn build_payload_rlp( diff --git a/src/server/service.rs b/src/server/service.rs index 76e13a3..3c0bff0 100644 --- a/src/server/service.rs +++ b/src/server/service.rs @@ -305,6 +305,7 @@ impl FkmsService for Server { .map_err(|_| Status::invalid_argument("Timestamp must be non-negative"))?; let request_id = tunnel_packet.sequence; + let script = flow::build_script(&signer_payload.contract_address); let payload_rlp = flow::build_payload_rlp( &signals, &signer_payload.address, @@ -312,7 +313,7 @@ impl FkmsService for Server { &signer_payload.block_id, signer_payload.key_index, signer_payload.sequence, - &signer_payload.script, + &script, resolve_time, request_id, )