block.go
1 package executor 2 3 import ( 4 "fmt" 5 "net/rpc" 6 7 "codeflow.dananglin.me.uk/apollo/enbas/internal/printer" 8 "codeflow.dananglin.me.uk/apollo/enbas/internal/server" 9 ) 10 11 func (b *BlockExecutor) Execute() error { 12 funcMap := map[string]func(*rpc.Client) error{ 13 resourceAccount: b.blockAccount, 14 } 15 16 doFunc, ok := funcMap[b.resourceType] 17 if !ok { 18 return UnsupportedTypeError{resourceType: b.resourceType} 19 } 20 21 client, err := server.Connect(b.config.Server, b.configDir) 22 if err != nil { 23 return fmt.Errorf("error creating the client for the daemon process: %w", err) 24 } 25 defer client.Close() 26 27 return doFunc(client) 28 } 29 30 func (b *BlockExecutor) blockAccount(client *rpc.Client) error { 31 accountID, err := getAccountID(client, false, b.accountName) 32 if err != nil { 33 return fmt.Errorf("received an error while getting the account ID: %w", err) 34 } 35 36 if err := client.Call("GTSClient.BlockAccount", accountID, nil); err != nil { 37 return fmt.Errorf("unable to block the account: %w", err) 38 } 39 40 printer.PrintSuccess(b.printSettings, "Successfully blocked the account.") 41 42 return nil 43 }