Skip to content

Commit fdb1da5

Browse files
authored
match tilt to new server svmbid format (#128)
1 parent bbf5119 commit fdb1da5

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

auction-server/src/auction.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ use {
7979
Deserializer,
8080
Serialize,
8181
},
82-
solana_sdk::transaction::Transaction,
82+
solana_sdk::transaction::VersionedTransaction,
8383
sqlx::types::time::OffsetDateTime,
8484
std::{
8585
result,
@@ -635,7 +635,7 @@ pub struct BidSvm {
635635
/// The transaction for bid.
636636
#[schema(example = "SGVsbG8sIFdvcmxkIQ==", value_type = String)]
637637
#[serde(with = "crate::serde::svm_transaction")]
638-
pub transaction: Transaction,
638+
pub transaction: VersionedTransaction,
639639
}
640640

641641
#[derive(Serialize, ToSchema, Debug, Clone)]

auction-server/src/serde.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ pub mod svm_transaction {
103103
Deserializer,
104104
Serializer,
105105
},
106-
solana_sdk::transaction::Transaction,
106+
solana_sdk::transaction::VersionedTransaction,
107107
};
108108

109-
pub fn serialize<S>(t: &Transaction, s: S) -> Result<S::Ok, S::Error>
109+
pub fn serialize<S>(t: &VersionedTransaction, s: S) -> Result<S::Ok, S::Error>
110110
where
111111
S: Serializer,
112112
{
@@ -115,15 +115,15 @@ pub mod svm_transaction {
115115
s.serialize_str(base64_encoded.as_str())
116116
}
117117

118-
pub fn deserialize<'de, D>(d: D) -> Result<Transaction, D::Error>
118+
pub fn deserialize<'de, D>(d: D) -> Result<VersionedTransaction, D::Error>
119119
where
120120
D: Deserializer<'de>,
121121
{
122122
let s: String = Deserialize::deserialize(d)?;
123123
let base64_decoded = STANDARD
124124
.decode(s)
125125
.map_err(|e| D::Error::custom(e.to_string()))?;
126-
let transaction: Transaction =
126+
let transaction: VersionedTransaction =
127127
bincode::deserialize(&base64_decoded).map_err(|e| D::Error::custom(e.to_string()))?;
128128
Ok(transaction)
129129
}

per_sdk/svm/dummy_tx.py

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import asyncio
3+
import base64
34
import hashlib
45
import logging
56
import struct
@@ -8,11 +9,14 @@
89
import httpx
910
from solana.rpc.async_api import AsyncClient
1011
from solana.transaction import Transaction
12+
from solders.hash import Hash
1113
from solders.instruction import AccountMeta, Instruction
12-
from solders.message import Message
14+
from solders.message import MessageV0
15+
from solders.null_signer import NullSigner
1316
from solders.pubkey import Pubkey
1417
from solders.system_program import ID as system_pid
1518
from solders.sysvar import INSTRUCTIONS as sysvar_ixs_pid
19+
from solders.transaction import VersionedTransaction
1620

1721
from per_sdk.svm.helpers import configure_logger, read_kp_from_json
1822

@@ -73,6 +77,12 @@ def parse_args() -> argparse.Namespace:
7377
default=False,
7478
help="Submit the transaction directly on-chain instead of submitting to the server",
7579
)
80+
parser.add_argument(
81+
"--use-legacy-transaction-bid",
82+
action="store_true",
83+
default=False,
84+
help="Use the legacy transaction message format instead of the versioned message format for the bid. Only applies if transaction is submitted as a bid (i.e. --submit-on-chain is not set)",
85+
)
7686
return parser.parse_args()
7787

7888

@@ -138,27 +148,37 @@ async def main():
138148
],
139149
)
140150

141-
tx = Transaction()
142-
tx.add(ix_submit_bid)
143-
tx.add(ix_dummy)
144-
145151
if args.submit_on_chain:
146152
client = AsyncClient(args.rpc_url, "confirmed")
153+
tx = Transaction(fee_payer=kp_searcher.pubkey())
154+
tx.add(ix_submit_bid)
155+
tx.add(ix_dummy)
147156
tx_sig = (
148157
await client.send_transaction(tx, kp_searcher, kp_relayer_signer)
149158
).value
150159
conf = await client.confirm_transaction(tx_sig)
151160
assert conf.value[0].status is None, "Transaction failed"
152161
logger.info(f"Submitted transaction with signature {tx_sig}")
153162
else:
154-
tx.sign_partial(kp_searcher)
155-
message = bytes(Message([ix_submit_bid, ix_dummy], pk_searcher))
156-
# TODO: impute one signature into the message
163+
if args.use_legacy_transaction_bid:
164+
tx = Transaction(fee_payer=kp_searcher.pubkey())
165+
tx.add(ix_submit_bid)
166+
tx.add(ix_dummy)
167+
tx.sign_partial(kp_searcher)
168+
serialized = base64.b64encode(
169+
tx.serialize(verify_signatures=False)
170+
).decode()
171+
else:
172+
messagev0 = MessageV0.try_compile(
173+
kp_searcher.pubkey(), [ix_submit_bid, ix_dummy], [], Hash.default()
174+
)
175+
signers = [kp_searcher, NullSigner(kp_relayer_signer.pubkey())]
176+
partially_signed = VersionedTransaction(messagev0, signers)
177+
serialized = base64.b64encode(bytes(partially_signed)).decode()
178+
157179
bid_body = {
158-
"permission_key": str(permission),
159180
"chain_id": "solana",
160-
"amount": args.bid,
161-
"transaction": message.hex(),
181+
"transaction": serialized,
162182
}
163183
client = httpx.AsyncClient()
164184
resp = await client.post(

0 commit comments

Comments
 (0)