func decode(c btncrypt.Cipher, stx *storedbtx) (inodedb.DBTransaction, error) { jsonop, err := btncrypt.Decrypt(c, stx.OpsJSON, len(stx.OpsJSON)-c.FrameOverhead()) if err != nil { return inodedb.DBTransaction{}, fmt.Errorf("Failed to decrypt OpsJSON: %v", err) } ops, err := inodedb.DecodeDBOperationsFromJson(jsonop) if err != nil { return inodedb.DBTransaction{}, err } return inodedb.DBTransaction{TxID: inodedb.TxID(stx.TxID), Ops: ops}, nil }
func TestCachedDBTransactionLogIO_1000Tx(t *testing.T) { be := idb.NewSimpleDBTransactionLogIO() ctxio := idb.NewCachedDBTransactionLogIO(be) for i := idb.TxID(1); i <= 1000; i++ { if err := ctxio.AppendTransaction(testTx(i)); err != nil { t.Errorf("AppendTransaction failed: %v", err) } } txs, err := ctxio.QueryTransactions(800) if err != nil { t.Errorf("QueryTransactions failed: %v", err) } txs2, err := be.QueryTransactions(800) if err != nil { t.Errorf("be.QueryTransactions failed: %v", err) } if !reflect.DeepEqual(txs, txs2) { t.Errorf("mismatch %+v != %+v", txs, txs2) } }
func main() { log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile) flag.Usage = Usage flag.Parse() cfg, err := facade.NewConfig(*flagConfigDir) if err != nil { log.Printf("%v", err) Usage() os.Exit(2) } minID := inodedb.LatestVersion if flag.NArg() < 1 { Usage() os.Exit(2) } switch flag.Arg(0) { case "purge": if flag.NArg() != 1 { Usage() os.Exit(2) } case "query": switch flag.NArg() { case 1: break case 2: n, err := strconv.ParseInt(flag.Arg(1), 10, 64) if err != nil { Usage() os.Exit(2) } minID = inodedb.TxID(n) break } break default: log.Printf("Unknown cmd: %v", flag.Arg(0)) Usage() os.Exit(2) } tsrc, err := auth.GetGCloudTokenSource(context.Background(), cfg.CredentialsFilePath, cfg.TokenCacheFilePath, false) if err != nil { log.Fatalf("Failed to init GCloudClientSource: %v", err) } key := btncrypt.KeyFromPassword(cfg.Password) c, err := btncrypt.NewCipher(key) if err != nil { log.Fatalf("Failed to init btncrypt.Cipher: %v", err) } dscfg := datastore.NewConfig(cfg.ProjectName, cfg.BucketName, c, tsrc) txlogio := datastore.NewDBTransactionLogIO(dscfg) switch flag.Arg(0) { case "purge": if err := txlogio.DeleteAllTransactions(); err != nil { log.Printf("DeleteAllTransactions() failed: %v", err) } case "query": txs, err := txlogio.QueryTransactions(minID) if err != nil { log.Printf("QueryTransactions() failed: %v", err) } for _, tx := range txs { fmt.Printf("%s\n", tx) } default: log.Printf("Unknown cmd: %v", flag.Arg(0)) os.Exit(1) } }