Documentation ¶
Index ¶
- Constants
- Variables
- func CanAuthBeDeleted(auth *Auth) bool
- func IsSourceIDRequired(source string) bool
- func IsValidOperation(op VmOperation) bool
- func MaxExecutionTimeFromFuel(fuel Fuel) time.Duration
- type AppClaims
- type Auth
- type AuthUserOptions
- type Auths
- type Contract
- type Contracts
- type Fuel
- type FuelStat
- type Revision
- type RevisionNumber
- type RevisionVersion
- type Revisions
- type State
- type StateValue
- type TokenPair
- type User
- type UserParams
- type Users
- type Visibility
- type VmOperation
- type VmState
Constants ¶
const ( AuthSourceLocal = "local" AuthSourceGitHub = "github" )
Authentication providers.
const ( VisibilityPrivate = "private" VisibilityPublic = "public" )
Visibility consts for the visibility of the contract.
const ( FuelInstantActionAmount = Fuel(50) FuelQuickActionAmount = Fuel(200) FuelFastestActionAmount = Fuel(400) FuelFastActionAmount = Fuel(600) FuelMidActionAmount = Fuel(800) FuelSlowActionAmount = Fuel(1200) FuelLongActionAmount = Fuel(2500) FuelExtremeActionAmount = Fuel(5000) FuelAbsoluteActionAmount = Fuel(10000) )
Fuel*ActionCost rappresents the cost of an action. Greater is the execution time, greater is the cost.
const ( AccessTokenExpiration = 60 * time.Minute // 1 hour RefreshTokenExpiration = 60 * 24 * 15 * time.Minute // 15 days )
const ( // NotDefinedOperationCost is the default fuel used if not specified by the VmCall when NotDefinedOperationCost = Fuel(25) // StateFulOperationCost is the extra fuel used when the operation is executed in the full state. StateFulOperationCost = Fuel(500) )
const (
// EmptyState is the empty state.
EmptyState = `{}`
)
const (
// UserNameInvalidCharacters defines all invalid characters for a user name.
UserNameInvalidCharacters = "!@#$%^&*()+=[]{}|\\;:'\"<>,/?`~"
)
Variables ¶
var FuelRefillAmount = Fuel(FuelTankCapacity * 5 / 100)
FuelRefillAmount retruns how much fuel is refilled at a time. It is equivalent to 5% of the capacity of the fuel tank. This is the default value that may be overwritten by the init function.
var FuelRefillRate = 400 * time.Millisecond
FuelRefillRate returns the rate of fuel refill. This is the default value that may be overwritten by the init function.
var FuelTankCapacity = 100 * vKFuel
FuelTankCapacity is the maximum capacity of the fuel tank. This is the default value that may be overwritten by the init function.
var MaxExecutionTime = 10 * time.Second
MaxExecutionTime returns the maximum execution time of an action. This is the default value that may be overwritten by the init function.
Functions ¶
func CanAuthBeDeleted ¶
CanAuthBeDeleted returns if the passed authentication source can be deleted.
func IsSourceIDRequired ¶
IsSourceIDRequired returns if the authentication source requires a source ID.
func IsValidOperation ¶
func IsValidOperation(op VmOperation) bool
IsValidOperation returns true if the operation is valid.
func MaxExecutionTimeFromFuel ¶
MaxExecutionTime returns the maximum execution time of the contract. MaxExecutionTime is based on max fuel compared with fuelAmountTable.
Types ¶
type AppClaims ¶
type AppClaims struct { jwt.StandardClaims Auth *Auth `json:"auth"` }
AppClaims is a custom claims type for JWT It contains the information about the user and the standard claims
type Auth ¶
type Auth struct { ID int64 `json:"id"` UserID int64 `json:"user_id"` Source string `json:"source"` SourceID null.String `json:"-"` AccessToken null.String `json:"-"` RefreshToken null.String `json:"-"` Expiry null.Time `json:"-"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` User *User `json:"user"` }
Auth represents a set of OAuth credentials. These are linked to a User so a single user could authenticate through multiple providers.
The authentication system links users by email address, however, some GitHub users don't provide their email publicly so we may not be able to link them by email address.
type AuthUserOptions ¶
type AuthUserOptions struct { AuthCode *string Source *string UserParams *UserParams }
AuthUserOptions represents the options for a user during fetching auth service.
type Contract ¶
type Contract struct { ID int64 `json:"id"` Name string `json:"name"` Description string `json:"description"` UserID int64 `json:"user_id"` Visibility Visibility `json:"visibility"` MaxFuel Fuel `json:"max_fuel"` // The maximum amount of fuel that can be burned from the contract. Stateful bool `json:"stateful"` // Enables the contract to persist its state during different executions (of same revision). CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` // avoid to access this field directly because it can be nil, use the Revision method UnwrapRevision instead. LastRevision *Revision `json:"last_revision"` User *User `json:"user"` }
Contract represents a contract. The contract is a cloud function that is executed on a server, deployed by users; The contract can have multiple revisions.
func (*Contract) MaxExecutionTime ¶
MaxExecutionTime returns the maximum execution time of the contract. MaxExecutionTime is based on max fuel compared with fuelAmountTable.
func (*Contract) UnwrapRevision ¶
UnwrapRevision returns the last revision of the contract if it exists, otherwise error is returned.
type Fuel ¶
type Fuel uint64
Fuel is a virtual unit of measure for the power consuption of the MusicGang VM. Like the real world, the fuel is limited, so the VM will stop if the fuel usage reaches the max capacity.
func FuelAmount ¶
FuelAmount returns the cost of an action based only on the execution time.
func FuelFromCustomFuel ¶ added in v0.0.7
func ParseFuel ¶ added in v0.0.7
ParseFuel accepts a string and returns a Fuel unit measurement, like the vFuel, vKFuel, vMFuel, vGFuel, vTFuel. for an example, 10 vKFuel is equal to 10 * 1024 = 10240.
func VmOperationCost ¶
func VmOperationCost(op VmOperation) Fuel
VmOperationCost returns the cost of the operation.
func (Fuel) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
type FuelStat ¶
type FuelStat struct { FuelCapacity Fuel `json:"fuel_capacity"` FuelUsed Fuel `json:"fuel_used"` LastRefuelAmout Fuel `json:"last_refuel_amount"` LastRefuelAt time.Time `json:"last_refuel_at"` }
FuelStats represents the statistics of the fuel tank.
type Revision ¶
type Revision struct { ID int64 `json:"id"` CreatedAt time.Time `json:"created_at"` Rev RevisionNumber `json:"rev"` Version RevisionVersion `json:"version"` ContractID int64 `json:"contract_id"` Notes string `json:"notes"` CompiledCode []byte `json:"-"` MaxFuel Fuel `json:"max_fuel"` Contract *Contract `json:"contract"` }
Revision represents a revision of a contract. Each revision is a snapshot of the contract state.
type RevisionVersion ¶
type RevisionVersion string
RevisionVersion indicates the version of revision management system.
const ( AnchorageVersion RevisionVersion = "Anchorage" CurrentRevisionVersion RevisionVersion = AnchorageVersion )
This is a list of all revisions versions.
type State ¶
type State struct { ID int64 `json:"id"` RevisionID int64 `json:"revision_id"` Value StateValue `json:"value"` UserID int64 `json:"user_id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` User *User `json:"user"` Revision *Revision `json:"revision"` }
State represents the state of the contract at a given revision for specific user. State enables contract to persist its state during different executions. The state should not be shared between users and different revisions.
type StateValue ¶ added in v0.0.7
StateValue represents the state value.
func NewStateFromBytes ¶ added in v0.0.7
func NewStateFromBytes(b []byte) (StateValue, error)
NewStateFromBytes creates a state from bytes. If b is nil, it returns an empty state.
func (*StateValue) Scan ¶ added in v0.0.7
func (s *StateValue) Scan(src any) error
Scan implements sql.Scanner
type TokenPair ¶
type TokenPair struct { AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` TokenType string `json:"token_type"` Expiry int64 `json:"expires_in"` }
TokenPair is a struct that contains the tokens and the expiration time
type User ¶
type User struct { ID int64 `json:"id"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` Email null.String `json:"email"` Name string `json:"name"` Password null.String `json:"-"` // List of associated OAuth authentication objects. // Currently only GitHub is supported so there should only be a maximum of one. Auths []*Auth `json:"auths"` }
User represents a user in the system. Users are typically created via OAuth using the AuthService but users can also be created directly for testing.
func (*User) AvatarURL ¶
AvatarURL returns a URL to the avatar image for the user. This loops over all auth providers to find the first available avatar. Currently only GitHub is supported. Returns blank string if no avatar URL available.
func (*User) CanCreateContract ¶
CanCreateContract returns if user is authorized to created contracts.
type UserParams ¶
UserParams represents the parameters for a user authentication.
type Visibility ¶
type Visibility string
Visibility defines the visibility of a contract.
func (Visibility) Validate ¶
func (v Visibility) Validate() error
Validate validates the visibility.
type VmOperation ¶
type VmOperation string
VmOperation is a type for the operations of the MusicGang VM.
const ( VmOperationCreateContract VmOperation = "create-contract" VmOperationExecuteContract VmOperation = "execute-contract" VmOperationUpdateContract VmOperation = "update-contract" VmOperationDeleteContract VmOperation = "delete-contract" VmOperationMakeContractRevision VmOperation = "make-contract-revision" VmOperationCreateUser VmOperation = "create-user" VmOperationUpdateUser VmOperation = "update-user" VmOperationDeleteUser VmOperation = "delete-user" VmOperationAuthenticate VmOperation = "authenticate" VmOperationCreateAuth VmOperation = "create-auth" VmOperationDeleteAuth VmOperation = "delete-auth" VmOperationVmStats VmOperation = "vm-stats" VmOperationGeneric VmOperation = "generic" )
Defines the operations of the MusicGang VM.