11import * as StellarSdk from '@stellar/stellar-sdk' ;
2- import { signTransaction } from '@stellar/freighter-api' ;
32
43const HORIZON_URL = process . env . NEXT_PUBLIC_HORIZON_URL ?? 'https://horizon-testnet.stellar.org' ;
54const server = new StellarSdk . Horizon . Server ( HORIZON_URL ) ;
@@ -11,41 +10,6 @@ function decodeBase64(value: string): string {
1110 return Buffer . from ( value , 'base64' ) . toString ( ) ;
1211}
1312
14- /**
15- * Build, sign with Freighter, and submit a vote transaction.
16- * @param prId GitHub PR number registered by the Vero Relayer
17- * @param publicKey Guardian's Stellar public key from WalletContext
18- */
19- export async function castVote ( prId : number , publicKey : string ) : Promise < string > {
20- const account = await server . loadAccount ( publicKey ) ;
21-
22- const tx = new StellarSdk . TransactionBuilder ( account , {
23- fee : StellarSdk . BASE_FEE ,
24- networkPassphrase : StellarSdk . Networks . TESTNET ,
25- } )
26- . addOperation (
27- StellarSdk . Operation . manageData ( { name : `vote_${ prId } ` , value : 'approve' } )
28- )
29- . setTimeout ( 30 )
30- . build ( ) ;
31-
32- const signed = await signTransaction ( tx . toXDR ( ) , {
33- networkPassphrase : StellarSdk . Networks . TESTNET ,
34- address : publicKey ,
35- } ) ;
36- if ( signed . error ) {
37- throw new Error ( signed . error . message ?? 'Freighter failed to sign the vote transaction' ) ;
38- }
39- if ( ! signed . signedTxXdr ) {
40- throw new Error ( 'Freighter did not return a signed transaction. Unlock Freighter and try again.' ) ;
41- }
42-
43- const result = await server . submitTransaction (
44- StellarSdk . TransactionBuilder . fromXDR ( signed . signedTxXdr , StellarSdk . Networks . TESTNET )
45- ) ;
46- return result . hash ;
47- }
48-
4913/** Fetch Guardian reputation score from contract data entries. */
5014export async function getReputation ( publicKey : string ) : Promise < number > {
5115 const account = await server . loadAccount ( publicKey ) ;
0 commit comments