factomapi

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2015 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuyEntryCredit

func BuyEntryCredit(version uint16, ecPubKey *notaryapi.Hash, from *notaryapi.Hash, value uint64, fee uint64, sig *notaryapi.Signature) error

This method will be replaced with a Factoid transaction once we have the factoid implementation in place

func CommitChain

func CommitChain(c *notaryapi.EChain) error

-------------------------------------

// PrintEntry is a helper function for debugging entry transport and encoding

func PrintEntry(e *Entry) {
	fmt.Println("ChainID:", hex.EncodeToString(e.ChainID))
	fmt.Println("ExtIDs:")
	for i := range e.ExtIDs {
		fmt.Println("	", string(e.ExtIDs[i]))
	}
	fmt.Println("Data:", string(e.Data))
}

// NewEntry creates a factom entry. It is supplied a string chain id, a []byte // of data, and a series of string external ids for entry lookup

func NewEntry(cid string, eids []string, data []byte) (e *Entry, err error) {
	e = new(Entry)
	e.ChainID, err = hex.DecodeString(cid)
	if err != nil {
		return nil, err
	}
	e.Data = data
	for _, v := range eids {
		e.ExtIDs = append(e.ExtIDs, []byte(v))
	}
	return
}

// NewChain creates a factom chain from a []string chain name and a new entry // to be the first entry of the new chain from []byte data, and a series of // string external ids

func NewChain(name []string, eids []string, data []byte) (c *Chain, err error) {
	c = new(Chain)
	for _, v := range name {
		c.Name = append(c.Name, []byte(v))
	}
	c.GenerateID()
	e := new(Entry)
	e.ChainID = c.ChainID
	e.Data = data
	for _, v := range eids {
		e.ExtIDs = append(e.ExtIDs, []byte(v))
	}
	c.FirstEntry = e
	return
}

// CommitEntry sends a message to the factom network containing a hash of the // entry to be used to verify the later RevealEntry.

func CommitEntry(e *Entry) error {
	data := url.Values{
		"datatype": {"entryhash"},
		"format":   {"binary"},
		"data":     {e.Hash()},
	}
	server := fmt.Sprintf(`http://%s/v1`, serverAddr)
	_, err := http.PostForm(server, data)
	if err != nil {
		return err
	}
	return nil
}

// RevealEntry sends a message to the factom network containing the binary // encoded entry for the server to add it to the factom blockchain. The entry // will be rejected if a CommitEntry was not done.

func RevealEntry(e *Entry) error {
	data := url.Values{
		"datatype": {"entry"},
		"format":   {"binary"},
		"entry":    {e.Hex()},
	}
	server := fmt.Sprintf(`http://%s/v1`, serverAddr)
	_, err := http.PostForm(server, data)
	if err != nil {
		return err
	}
	return nil
}

CommitChain sends a message to the factom network containing a series of hashes to be used to verify the later RevealChain.

func CommitEntry

func CommitEntry(e *notaryapi.Entry) error

CommitEntry sends a message to the factom network containing a hash of the entry to be used to verify the later RevealEntry.

func CommitEntry2

func CommitEntry2(e *Entry) error

CommitEntry sends a message to the factom network containing a hash of the entry to be used to verify the later RevealEntry.

func EXPLODE

func EXPLODE(obj interface{}) error

func GetDirectoryBlokByHashStr

func GetDirectoryBlokByHashStr(addr string) (*notaryapi.DBlock, error)

func GetDirectoryBloks

func GetDirectoryBloks(fromBlockHeight uint64, toBlockHeight uint64) (dBlocks []notaryapi.DBlock, err error)

func GetEntryBlokByHashStr

func GetEntryBlokByHashStr(addr string) (*notaryapi.EBlock, error)

func GetEntryBlokByMRStr

func GetEntryBlokByMRStr(addr string) (*notaryapi.EBlock, error)

func GetEntryByHashStr

func GetEntryByHashStr(addr string) (*notaryapi.Entry, error)

func GetEntryCreditBalance

func GetEntryCreditBalance(ecPubKey *notaryapi.Hash) (credits int32, err error)

func PrintEntry

func PrintEntry(e *Entry)

PrintEntry is a helper function for debugging entry transport and encoding

func RevealChain

func RevealChain(c *notaryapi.EChain) error

RevealChain sends a message to the factom network containing the binary encoded first entry for a chain to be used by the server to add a new factom chain. It will be rejected if a CommitChain was not done.

func RevealEntry

func RevealEntry(e *notaryapi.Entry) error

RevealEntry sends a message to the factom network containing the binary encoded entry for the server to add it to the factom blockchain. The entry will be rejected if a CommitEntry was not done.

func RevealEntry2

func RevealEntry2(e *Entry) error

RevealEntry sends a message to the factom network containing the binary encoded entry for the server to add it to the factom blockchain. The entry will be rejected if a CommitEntry was not done.

func SafeMarshal

func SafeMarshal(writer io.Writer, obj interface{}) error

func SafeMarshalHTML

func SafeMarshalHTML(writer io.Writer, obj interface{}) error

func SafeUnmarshal

func SafeUnmarshal(reader gocoding.SliceableRuneReader, obj interface{}) error

func SetDB

func SetDB(database database.Db) error

func SetOutMsgQueue

func SetOutMsgQueue(outMsgQ chan<- factomwire.Message) error

func SetServerAddr

func SetServerAddr(addr string) error

to be removed------------------------------

func Submit

func Submit(f FactomWriter) (err error)

CommitChain sends a message to the factom network containing a series of hashes to be used to verify the later RevealChain.

func CommitChain(c *Chain) error {
	var msg bytes.Buffer

	binary.Write(&msg, binary.BigEndian, uint64(time.Now().Unix()))
	msg.Write(c.MarshalBinary())

	chainhash, chainentryhash, entryhash := c.Hash()
	msg.Write([]byte(chainhash))
	msg.Write([]byte(chainentryhash))
	msg.Write([]byte(entryhash))

	sig := wallet.SignData(msg.Bytes())

	data := url.Values{
		"datatype": {"commitchain"},
		"format":   {"binary"},
		"signature": {hex.EncodeToString((*sig.Sig)[:])},
		"pubkey": 	{hex.EncodeToString((*sig.Pub.Key)[:])},
		"data":      {hex.EncodeToString(msg.Bytes())},

	}

	_, err := http.PostForm(server, data)
	if err != nil {
		return err
	}
	return nil
}

// RevealChain sends a message to the factom network containing the binary // encoded first entry for a chain to be used by the server to add a new factom // chain. It will be rejected if a CommitChain was not done.

func RevealChain(c *Chain) error {
	data := url.Values{
		"datatype": {"entry"},
		"format":   {"binary"},
		"data":     {hex.EncodeToString(c.MarshalBinary())},
	}
	_, err := http.PostForm(server, data)
	if err != nil {
		return err
	}
	return nil
}

Submit wraps CommitEntry and RevealEntry. Submit takes a FactomWriter (an entry is a FactomWriter) and does a commit and reveal for the entry adding it to the factom blockchain.

func SubmitFactoidTx

func SubmitFactoidTx(m factomwire.Message) error

Types

type Chain

type Chain struct {
	ChainID    []byte
	Name       [][]byte
	FirstEntry *Entry
}

A Chain that can be submitted to the factom network.

func NewChain

func NewChain(name []string, eids []string, data []byte) (c *Chain, err error)

NewChain creates a factom chain from a []string chain name and a new entry to be the first entry of the new chain from []byte data, and a series of string external ids

func (*Chain) CreateFactomChain

func (c *Chain) CreateFactomChain() *Chain

CreateFactomChain satisfies the FactomChainer interface.

func (*Chain) GenerateID

func (c *Chain) GenerateID() string

GenerateID will create the chainid from the chain name. It sets the chainid for the object and returns the chainid as a hex encoded string.

func (*Chain) Hash

func (c *Chain) Hash() (chain string, chain_entry string, entry string)

Hash will return a hex encoded hash of the chainid, a hash of the entry, and a hash of the chainid + entry to be used by CommitChain.

func (*Chain) Hex

func (c *Chain) Hex() string

Hex will return a hex encoded string of the binary chain.

func (*Chain) MarshalBinary

func (c *Chain) MarshalBinary() []byte

MarshalBinary creates a single []byte from a chain for transport.

func (*Chain) UnmarshalJSON

func (e *Chain) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON makes satisfies the json.Unmarshaler interfact and populates an entry with the data from a json entry.

type Entry

type Entry struct {
	ChainID []byte
	ExtIDs  [][]byte
	Data    []byte
}

A factom entry that can be submitted to the factom network.

func NewEntry

func NewEntry(cid string, eids []string, data []byte) (e *Entry, err error)

NewEntry creates a factom entry. It is supplied a string chain id, a []byte of data, and a series of string external ids for entry lookup

func (*Entry) CreateFactomEntry

func (e *Entry) CreateFactomEntry() *Entry

CreateFactomEntry allows an Entry to satisfy the FactomWriter interface.

func (*Entry) FromJsonEntry

func (e *Entry) FromJsonEntry(j jsonentry) (err error)

func (*Entry) Hash

func (e *Entry) Hash() string

Hash returns a hex encoded sha256 hash of the entry.

func (*Entry) Hex

func (e *Entry) Hex() string

Hex return the hex encoded string of the binary entry. Depricated!

func (*Entry) MarshalBinary

func (e *Entry) MarshalBinary() []byte

MarshalBinary creates a single []byte from an entry for transport.

func (*Entry) UnmarshalJSON

func (e *Entry) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON makes satisfies the json.Unmarshaler interfact and populates an entry with the data from a json entry.

type FactomChainer

type FactomChainer interface {
	CreateFactomChain() *Chain
}

Objects implimenting the FactomChainer interface may be used in the CreateChain call to create a chain and first entry on the factom network.

type FactomWriter

type FactomWriter interface {
	CreateFactomEntry() *Entry
}

Objects implimenting the FactomWriter interface may be used in the Submit call to create and add an entry to the factom network.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL