This repository has been archived by the owner on Aug 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: save swap information in database (#63)
- Loading branch information
1 parent
fdfeeaf
commit 0102760
Showing
14 changed files
with
293 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,12 @@ | ||
import { SwapUpdateEvent } from './Enums'; | ||
|
||
export type Error = { | ||
message: string; | ||
code: string; | ||
}; | ||
|
||
export type SwapUpdate = { | ||
event: SwapUpdateEvent, | ||
|
||
preimage?: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Sequelize from 'sequelize'; | ||
import * as db from '../../consts/Database'; | ||
|
||
export default (sequelize: Sequelize.Sequelize, dataTypes: Sequelize.DataTypes) => { | ||
const attributes: db.SequelizeAttributes<db.ReverseSwapAttributes> = { | ||
id: { type: dataTypes.STRING, primaryKey: true, allowNull: false }, | ||
pair: { type: dataTypes.STRING, allowNull: false }, | ||
status: { type: dataTypes.STRING, allowNull: true }, | ||
invoice: { type: dataTypes.STRING, allowNull: false }, | ||
preimage: { type: dataTypes.STRING, allowNull: true }, | ||
transactionId: { type: dataTypes.STRING, allowNull: false }, | ||
}; | ||
|
||
const options: Sequelize.DefineOptions<db.ReverseSwapInstance> = { | ||
tableName: 'reverseSwaps', | ||
}; | ||
|
||
const ReverseSwap = sequelize.define<db.ReverseSwapInstance, db.ReverseSwapAttributes>('ReverseSwap', attributes, options); | ||
|
||
ReverseSwap.associate = (models: Sequelize.Models) => { | ||
models.ReverseSwap.belongsTo(models.Pair, { | ||
foreignKey: 'pair', | ||
}); | ||
}; | ||
|
||
return ReverseSwap; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Sequelize from 'sequelize'; | ||
import * as db from '../../consts/Database'; | ||
|
||
export default (sequelize: Sequelize.Sequelize, dataTypes: Sequelize.DataTypes) => { | ||
const attributes: db.SequelizeAttributes<db.SwapAttributes> = { | ||
id: { type: dataTypes.STRING, primaryKey: true, allowNull: false }, | ||
pair: { type: dataTypes.STRING, allowNull: false }, | ||
status: { type: dataTypes.STRING, allowNull: true }, | ||
invoice: { type: dataTypes.STRING, unique: true, allowNull: false }, | ||
lockupAddress: { type: dataTypes.STRING, allowNull: false }, | ||
}; | ||
|
||
const options: Sequelize.DefineOptions<db.SwapInstance> = { | ||
tableName: 'swaps', | ||
indexes: [ | ||
{ | ||
unique: true, | ||
fields: ['id', 'invoice'], | ||
}, | ||
], | ||
}; | ||
|
||
const Swap = sequelize.define<db.SwapInstance, db.SwapAttributes>('Swap', attributes, options); | ||
|
||
Swap.associate = (models: Sequelize.Models) => { | ||
models.Swap.belongsTo(models.Pair, { | ||
foreignKey: 'pair', | ||
}); | ||
}; | ||
|
||
return Swap; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { WhereOptions } from 'sequelize'; | ||
import { Models } from '../db/Database'; | ||
import * as db from '../consts/Database'; | ||
|
||
class ReverseSwapRepository { | ||
constructor(private models: Models) {} | ||
|
||
public getReverseSwaps = async () => { | ||
return this.models.ReverseSwap.findAll({}); | ||
} | ||
|
||
public getReverseSwap = async (options: WhereOptions<db.ReverseSwapFactory>) => { | ||
return this.models.ReverseSwap.findOne({ | ||
where: options, | ||
}); | ||
} | ||
|
||
public addReverseSwap = async (reverseSwap: db.ReverseSwapFactory) => { | ||
return this.models.ReverseSwap.create(reverseSwap); | ||
} | ||
|
||
public setReverseSwapStatus = async (reverseSwap: db.ReverseSwapInstance, status: string) => { | ||
return reverseSwap.update({ | ||
status, | ||
}); | ||
} | ||
|
||
public updateReverseSwap = async (reverseSwap: db.ReverseSwapInstance, keys: object) => { | ||
return reverseSwap.update(keys); | ||
} | ||
} | ||
|
||
export default ReverseSwapRepository; |
Oops, something went wrong.