// Poll GetReserves() periodically from the fullnode.
Poll GetReserves() periodically from the fullnode.
// Poll GetReserves () periodically from the fullnode .
func PullPairReserves(fullNodeUrl string, pairs []common.Address, stopCh <-chan struct{}) (<-chan *pojo.PairReserve, error) {
	ctx := context.Background()
	ethClient, err := ethclient.DialContext(ctx, fullNodeUrl)
	if err != nil {
		return nil, err
	}
	blockNumber, err := NewBlockNumberOnFullnode(fullNodeUrl, stopCh)
	if err != nil {
		return nil, err
	}
	pairInstances := make([]*pair.Pair, 0)
	for _, pairAddress := range pairs {
		pairInstance, err := pair.NewPair(pairAddress, ethClient)
		if err != nil {
			return nil, err
		}
		pairInstances = append(pairInstances, pairInstance)
	}
	outCh := make(chan *pojo.PairReserve)
	go func() {
		visited := make(map[uint64]bool)
		for {
			select {
			case <-stopCh:
				close(outCh)
				return
			default:
				for i, pairInstance := range pairInstances {
					ret, err := pairInstance.GetReserves(nil)
					if err != nil {
						panic(err)
					}
					pairReserve := &pojo.PairReserve{
						Pair:               pairs[i],
						Reserve0:           pojo.NewBigInt(ret.Reserve0),
						Reserve1:           pojo.NewBigInt(ret.Reserve1),
						BlockTimestampLast: ret.BlockTimestampLast,
						BlockNumber:        blockNumber.Get().Int64(),
					}
					hash := pairReserve.Hash()
					if !visited[hash] {
						outCh <- pairReserve
						visited[hash] = true
					}
				}
			}
		}
	}()
	return outCh, nil
}
func PullPairReserves ( fullNodeUrl string , pairs [ ] common . Address , stopCh <- chan struct { } ) ( <- chan * pojo . PairReserve , error ) { ctx := context . Background ( ) ethClient , err := ethclient . DialContext ( ctx , fullNodeUrl ) if err != nil { return nil , err } blockNumber , err := NewBlockNumberOnFullnode ( fullNodeUrl , stopCh ) if err != nil { return nil , err } pairInstances := make ( [ ] * pair . Pair , 0 ) for _ , pairAddress := range pairs { pairInstance , err := pair . NewPair ( pairAddress , ethClient ) if err != nil { return nil , err } pairInstances = append ( pairInstances , pairInstance ) } outCh := make ( chan * pojo . PairReserve ) go func ( ) { visited := make ( map [ uint64 ] bool ) for { select { case <- stopCh : close ( outCh ) return default : for i , pairInstance := range pairInstances { ret , err := pairInstance . GetReserves ( nil ) if err != nil { panic ( err ) } pairReserve := & pojo . PairReserve { Pair : pairs [ i ] , Reserve0 : pojo . NewBigInt ( ret . Reserve0 ) , Reserve1 : pojo . NewBigInt ( ret . Reserve1 ) , BlockTimestampLast : ret . BlockTimestampLast , BlockNumber : blockNumber . Get ( ) . Int64 ( ) , } hash := pairReserve . Hash ( ) if ! visited [ hash ] { outCh <- pairReserve visited [ hash ] = true } } } } } ( ) return outCh , nil }
Poll GetReserves() periodically from the fullnode.
Poll GetReserves () periodically from the fullnode .