Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions ack.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ type EntryStatus struct {

func (e *EntryStatus) String() string {
var s string
if e.EntryHash != "" {
s += fmt.Sprintln("EntryHash:", e.EntryHash)
s += fmt.Sprintln("Status:", e.EntryData.Status)
s += fmt.Sprintln("Date:", e.EntryData.TransactionDateString)
}
s += fmt.Sprintln("TxID:", e.CommitTxID)
s += fmt.Sprintln("Status:", e.CommitData.Status)
s += fmt.Sprintln("Date:", e.CommitData.TransactionDateString)
Expand Down Expand Up @@ -66,9 +71,29 @@ type Malleated struct {
MalleatedTxIDs []string `json:"malleatedtxids"`
}

// EntryCommitACK takes the txid of the commit and searches for the entry/chain commit
func EntryCommitACK(txID, fullTransaction string) (*EntryStatus, error) {
params := ackRequest{Hash: txID, ChainID: "c", FullTransaction: fullTransaction}
req := NewJSON2Request("ack", APICounter(), params)
resp, err := factomdRequest(req)
if err != nil {
return nil, err
}
if resp.Error != nil {
return nil, resp.Error
}

eb := new(EntryStatus)
if err := json.Unmarshal(resp.JSONResult(), eb); err != nil {
return nil, err
}

return eb, nil
}

func FactoidACK(txID, fullTransaction string) (*FactoidTxStatus, error) {
params := ackRequest{TxID: txID, FullTransaction: fullTransaction}
req := NewJSON2Request("factoid-ack", APICounter(), params)
params := ackRequest{Hash: txID, ChainID: "f", FullTransaction: fullTransaction}
req := NewJSON2Request("ack", APICounter(), params)
resp, err := factomdRequest(req)
if err != nil {
return nil, err
Expand All @@ -85,9 +110,10 @@ func FactoidACK(txID, fullTransaction string) (*FactoidTxStatus, error) {
return eb, nil
}

func EntryACK(txID, fullTransaction string) (*EntryStatus, error) {
params := ackRequest{TxID: txID, FullTransaction: fullTransaction}
req := NewJSON2Request("entry-ack", APICounter(), params)
// EntryRevealACK will take the entryhash and search for the entry and the commit
func EntryRevealACK(entryhash, fullTransaction, chainiID string) (*EntryStatus, error) {
params := ackRequest{Hash: entryhash, ChainID: chainiID, FullTransaction: fullTransaction}
req := NewJSON2Request("ack", APICounter(), params)
resp, err := factomdRequest(req)
if err != nil {
return nil, err
Expand All @@ -103,3 +129,10 @@ func EntryACK(txID, fullTransaction string) (*EntryStatus, error) {

return eb, nil
}

// EntryACK is a deprecated call and SHOULD NOT BE USED.
// Use either EntryCommitAck or EntryRevealAck depending on the
// type of hash you are sending.
func EntryACK(entryhash, fullTransaction string) (*EntryStatus, error) {
return EntryRevealACK(entryhash, fullTransaction, "0000000000000000000000000000000000000000000000000000000000000000")
}
1 change: 1 addition & 0 deletions entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func CommitEntry(e *Entry, ec *ECAddress) (string, error) {
if err != nil {
return "", err
}

if resp.Error != nil {
return "", resp.Error
}
Expand Down
3 changes: 2 additions & 1 deletion wsapistructs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type heightRequest struct {
}

type ackRequest struct {
TxID string `json:"txid,omitempty"`
Hash string `json:"hash,omitempty"`
ChainID string `json:"chainid,omitempty"`
FullTransaction string `json:"fulltransaction,omitempty"`
}

Expand Down