@@ -10,10 +10,13 @@ import (
10
10
"path/filepath"
11
11
"strings"
12
12
"sync"
13
+ "time"
13
14
15
+ "github.com/0chain/gosdk/zboxcore/client"
14
16
"github.com/0chain/gosdk/zboxcore/fileref"
15
17
16
18
"github.com/0chain/gosdk/core/common"
19
+ "github.com/0chain/gosdk/core/transaction"
17
20
"github.com/0chain/gosdk/zboxcore/blockchain"
18
21
. "github.com/0chain/gosdk/zboxcore/logger"
19
22
"github.com/0chain/gosdk/zboxcore/marker"
25
28
notInitialized = common .NewError ("sdk_not_initialized" , "Please call InitStorageSDK Init and use GetAllocation to get the allocation object" )
26
29
)
27
30
31
+ type MetaOperation struct {
32
+ CrudType string
33
+ MetaData * ConsolidatedFileMeta
34
+ }
35
+
36
+ type MetaTransactionData struct {
37
+ TxnID string
38
+ MetaData * ConsolidatedFileMeta
39
+ }
40
+
28
41
type ConsolidatedFileMeta struct {
29
42
Name string
30
43
Type string
@@ -210,6 +223,7 @@ func (a *Allocation) uploadOrUpdateFile(localpath string, remotepath string, sta
210
223
}()
211
224
return nil
212
225
}
226
+
213
227
func (a * Allocation ) DownloadFile (localPath string , remotePath string , status StatusCallback ) error {
214
228
return a .downloadFile (localPath , remotePath , DOWNLOAD_CONTENT_FULL , status )
215
229
}
@@ -532,7 +546,7 @@ func (a *Allocation) GetAuthTicket(path string, filename string, referenceType s
532
546
authTicket , err := shareReq .GetAuthTicketForEncryptedFile (refereeClientID , refereeEncryptionPublicKey )
533
547
if err != nil {
534
548
return "" , err
535
- }
549
+ }
536
550
return authTicket , nil
537
551
538
552
}
@@ -615,3 +629,54 @@ func (a *Allocation) downloadFromAuthTicket(localPath string, authTicket string,
615
629
}()
616
630
return nil
617
631
}
632
+
633
+ func (a * Allocation ) CommitMetaTransaction (path , crudOperation string ) (* MetaTransactionData , error ) {
634
+ fileMeta , err := a .GetFileMeta (path )
635
+ if err != nil {
636
+ return nil , err
637
+ }
638
+
639
+ metaOperationData := & MetaOperation {
640
+ CrudType : crudOperation ,
641
+ MetaData : fileMeta ,
642
+ }
643
+ metaOperationBytes , err := json .Marshal (metaOperationData )
644
+ if err != nil {
645
+ return nil , err
646
+ }
647
+
648
+ txn := transaction .NewTransactionEntity (client .GetClientID (), blockchain .GetChainID (), client .GetClientPublicKey ())
649
+ txn .TransactionData = string (metaOperationBytes )
650
+ txn .TransactionType = transaction .TxnTypeData
651
+ err = txn .ComputeHashAndSign (client .Sign )
652
+ if err != nil {
653
+ return nil , err
654
+ }
655
+ transaction .SendTransactionSync (txn , blockchain .GetMiners ())
656
+ time .Sleep (5 * time .Second )
657
+ retries := 0
658
+ var t * transaction.Transaction
659
+ for retries < 5 {
660
+ t , err = transaction .VerifyTransaction (txn .Hash , blockchain .GetSharders ())
661
+ if err == nil {
662
+ break
663
+ }
664
+ retries ++
665
+ time .Sleep (5 * time .Second )
666
+ }
667
+
668
+ if err != nil {
669
+ Logger .Error ("Error verifying the commit transaction" , err .Error (), txn .Hash )
670
+ return nil , err
671
+ }
672
+ if t == nil {
673
+ return nil , common .NewError ("transaction_validation_failed" , "Failed to get the transaction confirmation" )
674
+ }
675
+
676
+ metaTransactionData := & MetaTransactionData {
677
+ TxnID : t .Hash ,
678
+ MetaData : metaOperationData .MetaData ,
679
+ }
680
+
681
+ return metaTransactionData , nil
682
+ }
0 commit comments