-
Notifications
You must be signed in to change notification settings - Fork 0
/
contract.go
33 lines (26 loc) · 941 Bytes
/
contract.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package tezos
import (
"encoding/json"
"fmt"
)
// Contract is an interface defines how a vault interact with the smart contract
type Contract interface {
Deploy(wallet *Wallet, arguments json.RawMessage) (address string, txID string, err error)
Call(wallet *Wallet, method string, arguments json.RawMessage) (tx *string, err error)
}
// ContractFactory is a function that takes an address and return a Contract instance
type ContractFactory func(string) Contract
// contracts is a singleton of all registered contract factory function
var contracts = map[string]ContractFactory{}
// GetContract returns
func GetContract(name string) ContractFactory {
return contracts[name]
}
// RegisterContract registers a contract
func RegisterContract(name string, contract ContractFactory) error {
if _, ok := contracts[name]; ok {
return fmt.Errorf("duplicated contract name has registered")
}
contracts[name] = contract
return nil
}