fabric-samples/full-stack-asset-transfer-guide/applications/trader-go/commands/create.go
nXtCyberNet cf7aa047c4 refactor the commands
Signed-off-by: nXtCyberNet <rohantech2005@gmail.com>
2026-06-10 21:22:59 +05:30

27 lines
635 B
Go

package commands
import (
"fmt"
"github.com/hyperledger/fabric-gateway/pkg/client"
)
// cmdCreate creates a new asset on the ledger.
// Arguments: <assetId> <ownerName> <color>
func cmdCreate(gw *client.Gateway, args []string) error {
if len(args) < 3 {
return fmt.Errorf("arguments: <assetId> <ownerName> <color>")
}
network := gw.GetNetwork(channelName())
contract := network.GetContract(chaincodeName())
smartContract := NewAssetTransfer(contract)
return smartContract.CreateAsset(Asset{
ID: args[0],
Owner: args[1],
Color: args[2],
Size: 1,
AppraisedValue: 1,
})
}