`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
- UNIQUE KEY `public_key` (`public_key`)
+ UNIQUE KEY `address` (`ip`,`port`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
LOCK TABLES `nodes` WRITE;
node.PublicKey = fmt.Sprintf("%v", node.XPub.PublicKey().String())
}
- ormNode := &orm.Node{PublicKey: node.PublicKey}
- if err := m.db.Where(&orm.Node{PublicKey: node.PublicKey}).First(ormNode).Error; err != nil && err != gorm.ErrRecordNotFound {
+ ormNode := &orm.Node{
+ IP: node.IP,
+ Port: node.Port,
+ }
+ if err := m.db.Where(ormNode).First(ormNode).Error; err != nil && err != gorm.ErrRecordNotFound {
return err
}
+ ormNode.PublicKey = node.PublicKey
if node.XPub != nil {
ormNode.Xpub = node.XPub.String()
}
- ormNode.IP = node.IP
- ormNode.Port = node.Port
- return m.db.Where(&orm.Node{PublicKey: ormNode.PublicKey}).
- Assign(&orm.Node{
- Xpub: ormNode.Xpub,
- IP: ormNode.IP,
- Port: ormNode.Port,
- }).FirstOrCreate(ormNode).Error
+ log.Info("======================================================================")
+ return m.db.Save(ormNode).Error
}
// TODO: maybe return connected nodes here for checkStatus