package main
import (
"fmt"
"time"
)
type Product struct {
ID string
Name string
Price float64
Description string
}
type Factory struct {
ID string
Name string
Address string
}
type Supplier struct {
ID string
Name string
Address string
}
type Account struct {
ID string
Name string
Address string
}
type Contract struct {
ID string
Name string
Factory *Factory
Supplier *Supplier
Account *Account
}
func NewProduct(name string, price float64, description string) *Product {
return &Product{
ID: fmt.Sprintf("%s-%s", name, time.Now().Format("2006-01-02")),
Name: name,
Price: price,
Description: description,
}
}
func NewFactory(name string, address string) *Factory {
return &Factory{
ID: fmt.Sprintf("%s-%s", name, time.Now().Format("2006-01-02")),
Name: name,
Address: address,
}
}
func NewSupplier(name string, address string) *Supplier {
return &Supplier{
ID: fmt.Sprintf("%s-%s", name, time.Now().Format("2006-01-02")),
Name: name,
Address: address,
}
}
func NewAccount(name string, address string) *Account {
return &Account{
ID: fmt.Sprintf("%s-%s", name, time.Now().Format("2006-01-02")),
Name: name,
Address: address,
}
}
func NewContract(name string, factory *Factory, supplier *Supplier, account *Account) *Contract {
return &Contract{
ID: fmt.Sprintf("%s-%s", name, time.Now().Format("2006-01-02")),
Name: name,
Factory: factory,
Supplier: supplier,
Account: account,
}
}
func (c *Contract) CreateProduct(name string, price float64, description string) {
product := NewProduct(name, price, description)
c.Account.CreateProduct(product)
}
func (c *Contract) CreateFactory(name
很遗憾 图片未能显示出来
没能实现
要在Fabric2.4网络环境下部署自己编写的Go语言链码并实例化测试,您需要遵循以下步骤:
安装fabric-sdk:您需要安装fabric-sdk,它是fabric2.4的一部分,用于与fabric2.4进行交互。您可以从fabric-sdk的官方网站上下载最新版本的fabric-sdk。
创建一个新的fabric项目:在fabric-sdk的项目目录下,创建一个新的fabric项目。
编写Go语言链码:在您的项目目录下,创建一个名为“chaincode.go”的文件,并编写您的Go语言链码。链码应该包含您的区块链服务器的地址和端口号,以及您要使用的其他参数和配置。
编译链码:使用fabric-sdk的命令行工具或IDE(如Visual Studio Code)编译链码。在命令行工具中,您可以使用以下命令: