@@ -32,7 +32,7 @@ export interface ValidateTransferFields {
3232    /** `recipient` in the [Solana Pay spec](https://github.com/solana-labs/solana-pay/blob/master/SPEC.md#recipient). */ 
3333    recipient : Recipient ; 
3434    /** `amount` in the [Solana Pay spec](https://github.com/solana-labs/solana-pay/blob/master/SPEC.md#amount). */ 
35-     amount : Amount ; 
35+     amount ? : Amount ; 
3636    /** `spl-token` in the [Solana Pay spec](https://github.com/solana-labs/solana-pay/blob/master/SPEC.md#spl-token). */ 
3737    splToken ?: SPLToken ; 
3838    /** `reference` in the [Solana Pay spec](https://github.com/solana-labs/solana-pay/blob/master/SPEC.md#reference). */ 
@@ -51,12 +51,38 @@ export interface ValidateTransferFields {
5151 * 
5252 * @throws  {ValidateTransferError } 
5353 */ 
54+ 
55+ export  function  validateTransfer ( 
56+     connection : Connection , 
57+     signature : TransactionSignature , 
58+     {  recipient,  amount,  splToken,  reference,  memo } : ValidateTransferFields  &  {  amount : Amount  } , 
59+     options ?: {  commitment ?: Finality  } 
60+ ) : Promise < TransactionResponse > ; 
61+ 
62+ /** 
63+  * Check that a given transaction contains a valid Solana Pay transfer. 
64+  * 
65+  * @param  connection - A connection to the cluster. 
66+  * @param  signature - The signature of the transaction to validate. 
67+  * @param  fields - Fields of a Solana Pay transfer request to validate. 
68+  * @param  options - Options for `getTransaction`. 
69+  * 
70+  * @throws  {ValidateTransferError } 
71+  */ 
72+ 
73+ export  function  validateTransfer ( 
74+     connection : Connection , 
75+     signature : TransactionSignature , 
76+     {  recipient,  amount,  splToken,  reference,  memo } : ValidateTransferFields , 
77+     options ?: {  commitment ?: Finality  } 
78+ ) : Promise < [ transactionResponse : TransactionResponse ,  amount : Amount ] > ; 
79+ 
5480export  async  function  validateTransfer ( 
5581    connection : Connection , 
5682    signature : TransactionSignature , 
5783    {  recipient,  amount,  splToken,  reference,  memo } : ValidateTransferFields , 
5884    options ?: {  commitment ?: Finality  } 
59- ) : Promise < TransactionResponse >  { 
85+ ) : Promise < TransactionResponse   |   [ TransactionResponse ,   Amount ] >  { 
6086    const  response  =  await  connection . getTransaction ( signature ,  options ) ; 
6187    if  ( ! response )  throw  new  ValidateTransferError ( 'not found' ) ; 
6288
@@ -79,7 +105,10 @@ export async function validateTransfer(
79105    const  [ preAmount ,  postAmount ]  =  splToken 
80106        ? await  validateSPLTokenTransfer ( instruction ,  message ,  meta ,  recipient ,  splToken ,  reference ) 
81107        : await  validateSystemTransfer ( instruction ,  message ,  meta ,  recipient ,  reference ) ; 
82-     if  ( postAmount . minus ( preAmount ) . lt ( amount ) )  throw  new  ValidateTransferError ( 'amount not transferred' ) ; 
108+ 
109+     const  delta  =  postAmount . minus ( preAmount ) ; 
110+     if  ( delta . lt ( amount  ??  BigNumber ( 1 ) . div ( LAMPORTS_PER_SOL ) ) ) 
111+         throw  new  ValidateTransferError ( 'amount not transferred' ) ; 
83112
84113    if  ( memo  !==  undefined )  { 
85114        // Memo instruction must be the second to last instruction 
@@ -88,7 +117,9 @@ export async function validateTransfer(
88117        validateMemo ( instruction ,  memo ) ; 
89118    } 
90119
91-     return  response ; 
120+     if  ( amount )  return  response ; 
121+ 
122+     return  [ response ,  delta ] ; 
92123} 
93124
94125function  validateMemo ( instruction : TransactionInstruction ,  memo : string ) : void   { 
0 commit comments