2018-11-07 21:50:43 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2018 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-27 02:55:09 +00:00
|
|
|
|
|
|
|
package event_triggered
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/vulcanize/vulcanizedb/pkg/datastore/postgres"
|
|
|
|
)
|
|
|
|
|
2018-08-31 19:48:43 +00:00
|
|
|
type ERC20EventDatastore interface {
|
|
|
|
CreateTransfer(model *TransferModel, vulcanizeLogId int64) error
|
|
|
|
CreateApproval(model *ApprovalModel, vulcanizeLogId int64) error
|
2018-08-27 02:55:09 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 19:48:43 +00:00
|
|
|
type ERC20EventRepository struct {
|
2018-08-27 02:55:09 +00:00
|
|
|
*postgres.DB
|
|
|
|
}
|
|
|
|
|
2018-08-31 19:48:43 +00:00
|
|
|
func (repository ERC20EventRepository) CreateTransfer(transferModel *TransferModel, vulcanizeLogId int64) error {
|
2018-08-27 02:55:09 +00:00
|
|
|
_, err := repository.DB.Exec(
|
|
|
|
|
2018-08-28 16:45:31 +00:00
|
|
|
`INSERT INTO token_transfers (vulcanize_log_id, token_name, token_address, to_address, from_address, tokens, block, tx)
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
2018-08-27 02:55:09 +00:00
|
|
|
ON CONFLICT (vulcanize_log_id) DO NOTHING`,
|
2018-08-28 16:45:31 +00:00
|
|
|
vulcanizeLogId, transferModel.TokenName, transferModel.TokenAddress, transferModel.To, transferModel.From, transferModel.Tokens, transferModel.Block, transferModel.TxHash)
|
2018-08-27 02:55:09 +00:00
|
|
|
|
2018-08-31 19:48:43 +00:00
|
|
|
return err
|
2018-08-27 02:55:09 +00:00
|
|
|
}
|
|
|
|
|
2018-08-31 19:48:43 +00:00
|
|
|
func (repository ERC20EventRepository) CreateApproval(approvalModel *ApprovalModel, vulcanizeLogId int64) error {
|
2018-08-27 02:55:09 +00:00
|
|
|
_, err := repository.DB.Exec(
|
|
|
|
|
2018-08-28 16:45:31 +00:00
|
|
|
`INSERT INTO token_approvals (vulcanize_log_id, token_name, token_address, owner, spender, tokens, block, tx)
|
|
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
|
2018-08-27 02:55:09 +00:00
|
|
|
ON CONFLICT (vulcanize_log_id) DO NOTHING`,
|
2018-08-28 16:45:31 +00:00
|
|
|
vulcanizeLogId, approvalModel.TokenName, approvalModel.TokenAddress, approvalModel.Owner, approvalModel.Spender, approvalModel.Tokens, approvalModel.Block, approvalModel.TxHash)
|
2018-08-27 02:55:09 +00:00
|
|
|
|
2018-08-31 19:48:43 +00:00
|
|
|
return err
|
2018-08-27 02:55:09 +00:00
|
|
|
}
|