Example #1
0
func setup() (*Kaonashi, error) {
	configPath := "./conf/config_test.toml"
	k, err := NewKaonashi(configPath)
	if err != nil {
		return k, err
	}
	k.InitDB()
	notes := []Note{
		Note{
			Title:   "title01",
			Body:    null.NewString("body01", true),
			Created: time.Now().String(),
			Updated: time.Now().String(),
		},
		Note{
			Title:   "title01",
			Body:    null.NewString("body01", true),
			Created: time.Now().String(),
			Updated: time.Now().String(),
		},
	}
	for _, note := range notes {
		_, err := k.db.NamedExec(`
		INSERT INTO note (title, body, created, updated) VALUES
		(:title, :body, :created, :updated)
		`, note)
		if err != nil {
			log.Fatalf("%s", err)
			return k, err
		}
	}
	return k, nil
}
Example #2
0
// Memo returns the memo for this transaction, if there is one.
func (tx *Transaction) Memo() null.String {
	var (
		value string
		valid bool
	)
	switch tx.Envelope.Tx.Memo.Type {
	case xdr.MemoTypeMemoNone:
		value, valid = "", false
	case xdr.MemoTypeMemoText:
		value, valid = utf8.Scrub(tx.Envelope.Tx.Memo.MustText()), true
	case xdr.MemoTypeMemoId:
		value, valid = fmt.Sprintf("%d", tx.Envelope.Tx.Memo.MustId()), true
	case xdr.MemoTypeMemoHash:
		hash := tx.Envelope.Tx.Memo.MustHash()
		value, valid =
			base64.StdEncoding.EncodeToString(hash[:]),
			true
	case xdr.MemoTypeMemoReturn:
		hash := tx.Envelope.Tx.Memo.MustRetHash()
		value, valid =
			base64.StdEncoding.EncodeToString(hash[:]),
			true
	default:
		panic(fmt.Errorf("invalid memo type: %v", tx.Envelope.Tx.Memo.Type))
	}

	return null.NewString(value, valid)
}
Example #3
0
// Ledger adds a ledger to the current ingestion
func (ingest *Ingestion) Ledger(
	id int64,
	header *core.LedgerHeader,
	txs int,
	ops int,
) error {

	sql := ingest.ledgers.Values(
		CurrentVersion,
		id,
		header.Sequence,
		header.LedgerHash,
		null.NewString(header.PrevHash, header.Sequence > 1),
		header.Data.TotalCoins,
		header.Data.FeePool,
		header.Data.BaseFee,
		header.Data.BaseReserve,
		header.Data.MaxTxSetSize,
		time.Unix(header.CloseTime, 0).UTC(),
		time.Now().UTC(),
		time.Now().UTC(),
		txs,
		ops,
	)

	_, err := ingest.DB.Exec(sql)
	if err != nil {
		return err
	}

	return nil
}
Example #4
0
func TestCreateNote(t *testing.T) {
	k, err := setup()
	if err != nil {
		t.Fatalf("failed to init kaonashi: %s", err)
	}

	note := Note{
		Title:   "new note",
		Body:    null.NewString("new body", true),
		Created: time.Now().String(),
		Updated: time.Now().String(),
	}
	if err := createNote(k.db, note); err != nil {
		t.Errorf("failed: %s", err)
	}
	noteTitles, _ := getNoteTitles(k.db)
	if len(noteTitles) != 3 {
		t.Errorf("expected 3 but got %d", len(noteTitles))
	}
}
Example #5
0
func TestUpdateNote(t *testing.T) {
	k, err := setup()
	if err != nil {
		t.Fatalf("failed to init kaonashi: %s", err)
	}

	note := Note{
		ID:      1,
		Title:   "updated note",
		Body:    null.NewString("new body", true),
		Created: time.Now().String(),
		Updated: time.Now().String(),
	}

	if err = updateNote(k.db, note); err != nil {
		t.Errorf("failed: %s", err)
	}
	updatedNote, _ := getNote(k.db, strconv.Itoa(note.ID))
	if updatedNote.Title != "updated note" {
		t.Errorf("expected 'updated note' but got %s", updatedNote.Title)
	}

}
Example #6
0
// NextURI returns the next page URI.
func (p *Paginator) NextURI() null.String {
	if !p.HasNext() {
		return null.NewString("", false)
	}
	return null.StringFrom(GenerateURI(p.Limit, (p.Offset + p.Limit), p.Options))
}
Example #7
0
// PreviousURI returns the previous page URI.
func (p *Paginator) PreviousURI() null.String {
	if !p.HasPrevious() {
		return null.NewString("", false)
	}
	return null.StringFrom(GenerateURI(p.Limit, (p.Offset - p.Limit), p.Options))
}