Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func (repo *ContractRepo) Restore(
- addr string,
- source string,
- startBlock uint64,
- ) error {
- return repo.db.Unscoped().
- Model(&Contract{}).
- Where("contract_addr = ?", addr).
- Updates(map[string]interface{}{
- "deleted_at": 0,
- "source": source,
- "created_at_block_height": startBlock}).
- Error
- }
- func (repo *ContractRepo) GetContractByAddr(
- contractAddr string,
- unScoped bool,
- ) (Contract, error) {
- var contract Contract
- if unScoped {
- if res := repo.db.Unscoped().Where("contract_addr = ?", contractAddr).First(&contract); res.Error != nil {
- return Contract{}, res.Error
- }
- } else {
- if res := repo.db.Where("contract_addr = ?", contractAddr).First(&contract); res.Error != nil {
- return Contract{}, res.Error
- }
- }
- return contract, nil
- }
- // Check if contract address is existed
- existedContract, err := s.repos.GetContractRepo().GetContractByAddr(contract.ContractAddr, true)
- if err != nil {
- if err == consts.ErrRecordNotFound {
- // Add new imported contract to db
- err = s.repos.GetContractRepo().Create(contract)
- if err != nil {
- return err
- }
- } else {
- return err
- }
- } else {
- fmt.Println(existedContract.DeletedAt)
- if existedContract.DeletedAt != 0 {
- // Restore contract address
- err = s.repos.GetContractRepo().Restore(
- existedContract.ContractAddr,
- contract.Source,
- startBlock)
- if err != nil {
- return err
- }
- } else {
- return consts.ErrDuplicatedContractAddr
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement