ui/eth_tx.go
func (h *Handler) GetEthTransactions(tkn, relType, relID string,
	offset, limit uint) (*GetEthTransactionsResult, error) {
	logger := h.logger.Add("method", "GetEthTransactions", "relatedType",
		relType, "relatedID", relID, "limit", limit, "offset", offset)

	if !h.token.Check(tkn) {
		logger.Warn("access denied")
		return nil, ErrAccessDenied
	}

	conds := make([]string, 0)
	args := make([]interface{}, 0)
	// If the relType is `accountAggregated`, then gets an Ethereum
	// address of the account and find all transactions where this address
	// is the sender.
	if relType == AccountAggregatedType {
		var acc data.Account
		if err := h.findByPrimaryKey(
			logger, ErrAccountNotFound, &acc, relID); err != nil {
			return nil, err
		}
		args = append(args, acc.EthAddr)
		conds = append(
			conds,
			"addr_from="+h.db.Placeholder(len(args)))
	} else if relType != "" {
		args = append(args, relType)
		conds = append(
			conds,
			"related_type="+h.db.Placeholder(len(args)))
	}
	if relID != "" && relType != AccountAggregatedType {
		args = append(args, relID)
		conds = append(
			conds,
			"related_id="+h.db.Placeholder(len(args)))
	}

	tail := ""
	if len(conds) > 0 {
		tail = "WHERE " + strings.Join(conds, " AND ")
	}

	count, err := h.numberOfObjects(
		logger, data.EthTxTable.Name(), tail, args)
	if err != nil {
		return nil, err
	}

	offsetLimit := h.offsetLimit(offset, limit)

	sorting := `ORDER BY issued DESC`

	tail = fmt.Sprintf("%s %s %s", tail, sorting, offsetLimit)

	txs, err := h.selectAllFrom(logger, data.EthTxTable, tail, args...)
	if err != nil {
		return nil, err
	}

	ret := make([]data.EthTx, len(txs))

	for i, v := range txs {
		ret[i] = *v.(*data.EthTx)
	}
	return &GetEthTransactionsResult{ret, count}, nil
}
func (h *Handler) GetEthTransactions(tkn, relType, relID string,
	offset, limit uint) (*GetEthTransactionsResult, error) {
	logger := h.logger.Add("method", "GetEthTransactions", "relatedType",
		relType, "relatedID", relID, "limit", limit, "offset", offset)

	if !h.token.Check(tkn) {
		logger.Warn("access denied")
		return nil, ErrAccessDenied
	}

	conds := make([]string, 0)
	args := make([]interface{}, 0)
	// If the relType is `accountAggregated`, then gets an Ethereum
	// address of the account and find all transactions where this address
	// is the sender.
	if relType == AccountAggregatedType {
		var acc data.Account
		if err := h.findByPrimaryKey(
			logger, ErrAccountNotFound, &acc, relID); err != nil {
			return nil, err
		}
		args = append(args, acc.EthAddr)
		conds = append(
			conds,
			"addr_from="+h.db.Placeholder(len(args)))
	} else if relType != "" {
		args = append(args, relType)
		conds = append(
			conds,
			"related_type="+h.db.Placeholder(len(args)))
	}
	if relID != "" && relType != AccountAggregatedType {
		args = append(args, relID)
		conds = append(
			conds,
			"related_id="+h.db.Placeholder(len(args)))
	}

	tail := ""
	if len(conds) > 0 {
		tail = "WHERE " + strings.Join(conds, " AND ")
	}

	count, err := h.numberOfObjects(
		logger, data.EthTxTable.Name(), tail, args)
	if err != nil {
		return nil, err
	}

	offsetLimit := h.offsetLimit(offset, limit)

	sorting := `ORDER BY issued DESC`

	tail = fmt.Sprintf("%s %s %s", tail, sorting, offsetLimit)

	txs, err := h.selectAllFrom(logger, data.EthTxTable, tail, args...)
	if err != nil {
		return nil, err
	}

	ret := make([]data.EthTx, len(txs))

	for i, v := range txs {
		ret[i] = *v.(*data.EthTx)
	}
	return &GetEthTransactionsResult{ret, count}, nil
}
func ( h * Handler ) GetEthTransactions ( tkn , relType , relID string , offset , limit uint ) ( * GetEthTransactionsResult , error ) { logger := h . logger . Add ( " " , " " , " " , relType , " " , relID , " " , limit , " " , offset ) if ! h . token . Check ( tkn ) { logger . Warn ( " " ) return nil , ErrAccessDenied } conds := make ( [ ] string , 0 ) args := make ( [ ] interface { } , 0 ) // If the relType is `accountAggregated`, then gets an Ethereum // address of the account and find all transactions where this address // is the sender. if relType == AccountAggregatedType { var acc data . Account if err := h . findByPrimaryKey ( logger , ErrAccountNotFound , & acc , relID ) ; err != nil { return nil , err } args = append ( args , acc . EthAddr ) conds = append ( conds , " " + h . db . Placeholder ( len ( args ) ) ) } else if relType != " " { args = append ( args , relType ) conds = append ( conds , " " + h . db . Placeholder ( len ( args ) ) ) } if relID != " " && relType != AccountAggregatedType { args = append ( args , relID ) conds = append ( conds , " " + h . db . Placeholder ( len ( args ) ) ) } tail := " " if len ( conds ) > 0 { tail = " " + strings . Join ( conds , " " ) } count , err := h . numberOfObjects ( logger , data . EthTxTable . Name ( ) , tail , args ) if err != nil { return nil , err } offsetLimit := h . offsetLimit ( offset , limit ) sorting := `ORDER BY issued DESC` tail = fmt . Sprintf ( " " , tail , sorting , offsetLimit ) txs , err := h . selectAllFrom ( logger , data . EthTxTable , tail , args ... ) if err != nil { return nil , err } ret := make ( [ ] data . EthTx , len ( txs ) ) for i , v := range txs { ret [ i ] = * v . ( * data . EthTx ) } return & GetEthTransactionsResult { ret , count } , nil }
// GetEthTransactions returns transactions by related object.
GetEthTransactions returns transactions by related object .