From a692a38d28112e4f7b66d4c561aa7a479f571ecc Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 18 Feb 2025 00:49:18 +0100 Subject: [golang] update error handling and bootstrap trade procurement --- golang/pkg/agent/contracting.go | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'golang/pkg/agent/contracting.go') diff --git a/golang/pkg/agent/contracting.go b/golang/pkg/agent/contracting.go index a3eb7aa..6d67d6d 100644 --- a/golang/pkg/agent/contracting.go +++ b/golang/pkg/agent/contracting.go @@ -21,12 +21,12 @@ func (a *agent) autoContracting(ship *model.Ship) { now := time.Now() if now.Before(contract.Terms.Deadline) { if err := a.runContract(&contract, ship); err != nil { - a.channel <- fmt.Errorf("failed to run contracts with ship %s: %w", ship.Symbol, err) + a.channel <- fmt.Errorf("failed to run contract %s with ship %s: %w", contract.Id, ship.Symbol, err) return } } } - a.channel <- fmt.Errorf("failed to run contracts: negotiating new contracts is not implemented yet") + a.channel <- fmt.Errorf("negotiating new contracts is not implemented yet") // TODO //for { // negotiate @@ -36,14 +36,30 @@ func (a *agent) autoContracting(ship *model.Ship) { func (a *agent) runContract(contract *model.Contract, ship *model.Ship) error { if err := a.client.Accept(contract, a.db); err != nil { - return fmt.Errorf("failed to run contract: %w", err) + return fmt.Errorf("failed to accept contract: %w", err) } //slog.Info("running contract", "contract", contract, "ship", ship.Symbol) switch contract.Type { - // TODO - //case "PROCUREMENT": + case "PROCUREMENT": + if err := a.runProcurement(contract, ship); err != nil { + return fmt.Errorf("failed to run procurement: %w", err) + } default: - return fmt.Errorf("failed to run contract: handling contracts of type %s is not implemented yet", contract.Type) + return fmt.Errorf("handling contracts of type %s is not implemented yet", contract.Type) } return nil } + +func (a *agent) runProcurement(contract *model.Contract, ship *model.Ship) error { + deliveryCargo := contract.Terms.Deliver[0].TradeSymbol + deliveryWaypoint, err := a.client.GetWaypoint(contract.Terms.Deliver[0].DestinationSymbol, a.db) + if err != nil { + return fmt.Errorf("failed to get delivery waypoint: %w", err) + } + for !contract.Fullfilled { + _ = deliveryCargo + _ = deliveryWaypoint + return fmt.Errorf("not implemented") + } + return fmt.Errorf("not implemented") +} -- cgit v1.2.3