@@ -420,8 +420,11 @@ var (
420
420
421
421
// CreateTable creates a new table given the table name and column definitions
422
422
func (stub * ChaincodeStub ) CreateTable (name string , columnDefinitions []* ColumnDefinition ) error {
423
+ return createTableInternal (stub , name , columnDefinitions )
424
+ }
423
425
424
- _ , err := stub .getTable (name )
426
+ func createTableInternal (stub ChaincodeStubInterface , name string , columnDefinitions []* ColumnDefinition ) error {
427
+ _ , err := getTable (stub , name )
425
428
if err == nil {
426
429
return fmt .Errorf ("CreateTable operation failed. Table %s already exists." , name )
427
430
}
@@ -490,11 +493,15 @@ func (stub *ChaincodeStub) CreateTable(name string, columnDefinitions []*ColumnD
490
493
// GetTable returns the table for the specified table name or ErrTableNotFound
491
494
// if the table does not exist.
492
495
func (stub * ChaincodeStub ) GetTable (tableName string ) (* Table , error ) {
493
- return stub . getTable (tableName )
496
+ return getTable (stub , tableName )
494
497
}
495
498
496
499
// DeleteTable deletes an entire table and all associated rows.
497
500
func (stub * ChaincodeStub ) DeleteTable (tableName string ) error {
501
+ return deleteTableInternal (stub , tableName )
502
+ }
503
+
504
+ func deleteTableInternal (stub ChaincodeStubInterface , tableName string ) error {
498
505
tableNameKey , err := getTableNameKey (tableName )
499
506
if err != nil {
500
507
return err
@@ -527,7 +534,7 @@ func (stub *ChaincodeStub) DeleteTable(tableName string) error {
527
534
// false and a TableNotFoundError if the specified table name does not exist.
528
535
// false and an error if there is an unexpected error condition.
529
536
func (stub * ChaincodeStub ) InsertRow (tableName string , row Row ) (bool , error ) {
530
- return stub . insertRowInternal (tableName , row , false )
537
+ return insertRowInternal (stub , tableName , row , false )
531
538
}
532
539
533
540
// ReplaceRow updates the row in the specified table.
@@ -537,11 +544,15 @@ func (stub *ChaincodeStub) InsertRow(tableName string, row Row) (bool, error) {
537
544
// flase and a TableNotFoundError if the specified table name does not exist.
538
545
// false and an error if there is an unexpected error condition.
539
546
func (stub * ChaincodeStub ) ReplaceRow (tableName string , row Row ) (bool , error ) {
540
- return stub . insertRowInternal (tableName , row , true )
547
+ return insertRowInternal (stub , tableName , row , true )
541
548
}
542
549
543
550
// GetRow fetches a row from the specified table for the given key.
544
551
func (stub * ChaincodeStub ) GetRow (tableName string , key []Column ) (Row , error ) {
552
+ return getRowInternal (stub , tableName , key )
553
+ }
554
+
555
+ func getRowInternal (stub ChaincodeStubInterface , tableName string , key []Column ) (Row , error ) {
545
556
546
557
var row Row
547
558
@@ -571,13 +582,17 @@ func (stub *ChaincodeStub) GetRow(tableName string, key []Column) (Row, error) {
571
582
// also be called with A only to return all rows that have A and any value
572
583
// for C and D as their key.
573
584
func (stub * ChaincodeStub ) GetRows (tableName string , key []Column ) (<- chan Row , error ) {
585
+ return getRowsInternal (stub , tableName , key )
586
+ }
587
+
588
+ func getRowsInternal (stub ChaincodeStubInterface , tableName string , key []Column ) (<- chan Row , error ) {
574
589
575
590
keyString , err := buildKeyString (tableName , key )
576
591
if err != nil {
577
592
return nil , err
578
593
}
579
594
580
- table , err := stub . getTable (tableName )
595
+ table , err := getTable (stub , tableName )
581
596
if err != nil {
582
597
return nil , err
583
598
}
@@ -630,6 +645,10 @@ func (stub *ChaincodeStub) GetRows(tableName string, key []Column) (<-chan Row,
630
645
631
646
// DeleteRow deletes the row for the given key from the specified table.
632
647
func (stub * ChaincodeStub ) DeleteRow (tableName string , key []Column ) error {
648
+ return deleteRowInternal (stub , tableName , key )
649
+ }
650
+
651
+ func deleteRowInternal (stub ChaincodeStubInterface , tableName string , key []Column ) error {
633
652
634
653
keyString , err := buildKeyString (tableName , key )
635
654
if err != nil {
@@ -682,7 +701,7 @@ func (stub *ChaincodeStub) GetTxTimestamp() (*gp.Timestamp, error) {
682
701
return stub .securityContext .TxTimestamp , nil
683
702
}
684
703
685
- func (stub * ChaincodeStub ) getTable ( tableName string ) (* Table , error ) {
704
+ func getTable (stub ChaincodeStubInterface , tableName string ) (* Table , error ) {
686
705
687
706
tableName , err := getTableNameKey (tableName )
688
707
if err != nil {
@@ -808,7 +827,7 @@ func getKeyAndVerifyRow(table Table, row Row) ([]Column, error) {
808
827
return keys , nil
809
828
}
810
829
811
- func (stub * ChaincodeStub ) isRowPresent ( tableName string , key []Column ) (bool , error ) {
830
+ func isRowPresent (stub ChaincodeStubInterface , tableName string , key []Column ) (bool , error ) {
812
831
keyString , err := buildKeyString (tableName , key )
813
832
if err != nil {
814
833
return false , err
@@ -829,9 +848,9 @@ func (stub *ChaincodeStub) isRowPresent(tableName string, key []Column) (bool, e
829
848
// false and no error if a row already exists for the given key.
830
849
// false and a TableNotFoundError if the specified table name does not exist.
831
850
// false and an error if there is an unexpected error condition.
832
- func (stub * ChaincodeStub ) insertRowInternal ( tableName string , row Row , update bool ) (bool , error ) {
851
+ func insertRowInternal (stub ChaincodeStubInterface , tableName string , row Row , update bool ) (bool , error ) {
833
852
834
- table , err := stub . getTable (tableName )
853
+ table , err := getTable (stub , tableName )
835
854
if err != nil {
836
855
return false , err
837
856
}
@@ -841,7 +860,7 @@ func (stub *ChaincodeStub) insertRowInternal(tableName string, row Row, update b
841
860
return false , err
842
861
}
843
862
844
- present , err := stub . isRowPresent (tableName , key )
863
+ present , err := isRowPresent (stub , tableName , key )
845
864
if err != nil {
846
865
return false , err
847
866
}
0 commit comments