mirror of
https://github.com/ditatompel/xmr-remote-nodes.git
synced 2025-01-08 05:52:10 +07:00
Adding majority net fee
Note that because this app not caching "expensive" query from database, I use static majority data for frontend to reduce API call.
This commit is contained in:
parent
a40c81d881
commit
1ceb00543b
5 changed files with 72 additions and 4 deletions
|
@ -22,6 +22,6 @@ export async function load({ data }) {
|
||||||
description: metaDefaults.description,
|
description: metaDefaults.description,
|
||||||
image: metaDefaults.image
|
image: metaDefaults.image
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,41 @@
|
||||||
handler.invalidate();
|
handler.invalidate();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Array containing network fees.
|
||||||
|
* For now, I use static data to reduce the amount of API calls.
|
||||||
|
* See the values from `/api/v1/fees`
|
||||||
|
* @type {{ nettype: string, estimate_fee: number }[]}
|
||||||
|
*/
|
||||||
|
const netFees = [
|
||||||
|
{
|
||||||
|
nettype: 'mainnet',
|
||||||
|
estimate_fee: 20000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nettype: 'stagenet',
|
||||||
|
estimate_fee: 58000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nettype: 'testnet',
|
||||||
|
estimate_fee: 20000
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @type {Object.<string, number>} */
|
||||||
|
let majorityFee = netFees.reduce(
|
||||||
|
/**
|
||||||
|
* @param {Object.<string, number>} o
|
||||||
|
* @param {{ nettype: string, estimate_fee: number }} key
|
||||||
|
* @returns {Object.<string, number>}
|
||||||
|
*/
|
||||||
|
(o, key) => ({
|
||||||
|
...o,
|
||||||
|
[key.nettype]: key.estimate_fee
|
||||||
|
}),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
/** @type {number | undefined} */
|
/** @type {number | undefined} */
|
||||||
let intervalId;
|
let intervalId;
|
||||||
let intervalValue = 0;
|
let intervalValue = 0;
|
||||||
|
@ -274,11 +309,10 @@
|
||||||
/></td
|
/></td
|
||||||
>
|
>
|
||||||
<td>
|
<td>
|
||||||
<!-- <EstimateFeeCell
|
<EstimateFeeCell
|
||||||
estimate_fee={row.estimate_fee}
|
estimate_fee={row.estimate_fee}
|
||||||
majority_fee={netFees[row.nettype]}
|
majority_fee={majorityFee[row.nettype]}
|
||||||
/>
|
/>
|
||||||
-->
|
|
||||||
</td>
|
</td>
|
||||||
<td><UptimeCell uptime={row.uptime} /></td>
|
<td><UptimeCell uptime={row.uptime} /></td>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
@ -171,6 +171,15 @@ func AddNode(c *fiber.Ctx) error {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NetFee(c *fiber.Ctx) error {
|
||||||
|
moneroRepo := repo.NewMoneroRepo(database.GetDB())
|
||||||
|
return c.JSON(fiber.Map{
|
||||||
|
"status": "ok",
|
||||||
|
"message": "Success",
|
||||||
|
"data": moneroRepo.NetFee(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func GiveJob(c *fiber.Ctx) error {
|
func GiveJob(c *fiber.Ctx) error {
|
||||||
acceptTor := c.QueryInt("accept_tor", 0)
|
acceptTor := c.QueryInt("accept_tor", 0)
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ func V1Api(app *fiber.App) {
|
||||||
v1.Post("/prober", Prober)
|
v1.Post("/prober", Prober)
|
||||||
v1.Get("/nodes", MoneroNodes)
|
v1.Get("/nodes", MoneroNodes)
|
||||||
v1.Post("/nodes", AddNode)
|
v1.Post("/nodes", AddNode)
|
||||||
|
v1.Get("/fees", NetFee)
|
||||||
v1.Get("/job", CheckProber, GiveJob)
|
v1.Get("/job", CheckProber, GiveJob)
|
||||||
v1.Post("/job", CheckProber, ProcessJob)
|
v1.Post("/job", CheckProber, ProcessJob)
|
||||||
v1.Get("/crons", Crons)
|
v1.Get("/crons", Crons)
|
||||||
|
|
|
@ -20,6 +20,7 @@ type MoneroRepository interface {
|
||||||
Nodes(q MoneroQueryParams) (MoneroNodes, error)
|
Nodes(q MoneroQueryParams) (MoneroNodes, error)
|
||||||
GiveJob(acceptTor int) (MoneroNode, error)
|
GiveJob(acceptTor int) (MoneroNode, error)
|
||||||
ProcessJob(report ProbeReport, proberId int64) error
|
ProcessJob(report ProbeReport, proberId int64) error
|
||||||
|
NetFee() []NetFee
|
||||||
}
|
}
|
||||||
|
|
||||||
type MoneroRepo struct {
|
type MoneroRepo struct {
|
||||||
|
@ -307,3 +308,26 @@ func (repo *MoneroRepo) ProcessJob(report ProbeReport, proberId int64) error {
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type NetFee struct {
|
||||||
|
Nettype string `json:"nettype" db:"nettype"`
|
||||||
|
EstimateFee uint `json:"estimate_fee" db:"estimate_fee"`
|
||||||
|
NodeCount int `json:"node_count" db:"node_count"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repo *MoneroRepo) NetFee() []NetFee {
|
||||||
|
netTypes := [3]string{"mainnet", "stagenet", "testnet"}
|
||||||
|
netFees := []NetFee{}
|
||||||
|
|
||||||
|
for _, net := range netTypes {
|
||||||
|
fees := NetFee{}
|
||||||
|
err := repo.db.Get(&fees, `SELECT COUNT(id) AS node_count, nettype, estimate_fee FROM tbl_node WHERE nettype = ? GROUP BY estimate_fee ORDER BY node_count DESC LIMIT 1`, net)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("WARN:", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
netFees = append(netFees, fees)
|
||||||
|
}
|
||||||
|
|
||||||
|
return netFees
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue