admin - atticplaygroup/prex GitHub Wiki

Administrator Account

Prex includes an administrative account that possesses an unlimited supply of both free and sold quota, intended for distribution to other users. This account is also responsible for clearing out outdated accounts, deposit records, old purchase requests, and other obsolete data.

It is technically possible (and advisable) to divide the responsibilities of the administrative account into multiple distinct roles to improve overall security in the future.

Initialize DB

func (s *Server) InitDb(
	ctx context.Context,
) DbState {
	adminAccountId := s.initDbAdminAccount(ctx, s.config.AdminUsername)
	freeQuotaServiceUuid, _ := utils.Uuid2bytes("00000000-0000-0000-0000-000000000000")
	freeQuotaServiceId := s.initDbService(ctx, [16]byte(freeQuotaServiceUuid), "free quota service")
	soldQuotaServiceUuid, _ := utils.Uuid2bytes("00000000-0000-0000-0000-000000000001")
	soldQuotaServiceId := s.initDbService(ctx, [16]byte(soldQuotaServiceUuid), "sold quota service")
	s.initDbSoldServiceOrder(ctx, adminAccountId, freeQuotaServiceId)
	s.initAdminQuota(ctx, adminAccountId, soldQuotaServiceId)
	return DbState{
		AdminAccountId:     adminAccountId,
		FreeQuotaServiceId: freeQuotaServiceId,
		SoldQuotaServiceId: soldQuotaServiceId,
	}
}

Upon server initialization, three actions are performed:

  1. If it doesn't already exist, an administrative account is created.
  2. Free and sold quota services are established.
  3. The administrative account is granted a significant amount of both types of quota.

You can verify which tokens are available to claim in the fufilled_orders database table.

Managing Free and Sold Quota

Following initialization, external users can acquire quota tokens from the administrative account. The quantity, frequency, and price at which the administrator offers quota can be determined by factors such as the current system load and the estimated validity period of the tokens.

Free quota is directly placed in the active_orders table with an unlimited quantity. However, sold quota is stored in the fulfilled_orders table due to the following reasons:

  • The administrative account itself must claim sold quota in order to utilize it, or it will also be denied access.
  • Regular maintenance of the database and placement of sales orders are required.

Scheduled Database Maintenance

For Prex to remain sustainable, routine cleaning of inactive accounts and transactions is necessary. The operator can schedule automated tasks using cron jobs with the administrator account's AUTH_TOKEN to perform these tasks. The following items require periodic cleaning:

Table Condition
accounts expire_time has passed
active_orders service_expire_time or order_expire_time has been reached
fulfilled_orders service_expire_time has been reached
deposits epoch is older than deposit MAX_DEPOSIT_EPOCH_GAP and priviledge is normal user
withdraws withdraw_status is "success" and transaction is too old

The services table is managed manually.

⚠️ **GitHub.com Fallback** ⚠️