...
|
...
|
@@ -7,6 +7,7 @@ import ( |
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/application/factory"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/domain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/infrastructure/blockchain"
|
|
|
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-user/pkg/log"
|
|
|
"time"
|
|
|
)
|
|
|
|
...
|
...
|
@@ -41,20 +42,28 @@ func (blockChainService *BlockChainService) UpChain(upChainCommand *command.UpCh |
|
|
|
|
|
// 1. 查重
|
|
|
upChainRepository, _, _ := factory.FastPgUpChain(transactionContext, 0)
|
|
|
if item, err := upChainRepository.FindOne(map[string]interface{}{"source": upChain.Source, "primaryId": upChain.PrimaryId}); err == nil && item != nil {
|
|
|
return nil, fmt.Errorf("duplicate message %v %v", upChain.Source, upChain.PrimaryId)
|
|
|
// 可溯源数据,可重复上传,可以追溯历史修改记录
|
|
|
if len(upChain.IssueId) == 0 {
|
|
|
if item, err := upChainRepository.FindOne(map[string]interface{}{"source": upChain.Source, "primaryId": upChain.PrimaryId}); err == nil && item != nil {
|
|
|
return nil, fmt.Errorf("duplicate message %v %v", upChain.Source, upChain.PrimaryId)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 2.上链
|
|
|
bc := &blockchain.BSNBlockChain{
|
|
|
PublicPem: []byte(""),
|
|
|
Host: "",
|
|
|
PublicKey: "",
|
|
|
PublicPem: []byte(blockchain.PubPem),
|
|
|
Host: blockchain.Host,
|
|
|
PublicKey: blockchain.PubKey,
|
|
|
PrivatePem: blockchain.PriK,
|
|
|
EnableDebugLog: true,
|
|
|
}
|
|
|
options := blockchain.NewUpToChainOptions(upChain.Source, upChain.PrimaryId, upChain.Data).WithInnerPrimaryIssueId(upChain.IssueId)
|
|
|
upToChainResponse, err := bc.UpToChain(options)
|
|
|
if err != nil || upToChainResponse == nil {
|
|
|
upToChainResponse, e := bc.UpToChain(options)
|
|
|
if e != nil || upToChainResponse == nil {
|
|
|
upChain.UpFail()
|
|
|
if e != nil {
|
|
|
log.Logger.Error("up chain err:" + e.Error())
|
|
|
}
|
|
|
} else {
|
|
|
upChain.UpSuccess(string(*upToChainResponse))
|
|
|
}
|
...
|
...
|
|