diff --git a/ack.go b/ack.go index 3d6f124..72c87a8 100644 --- a/ack.go +++ b/ack.go @@ -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) @@ -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 @@ -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 @@ -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") +} diff --git a/entry.go b/entry.go index f2bacf8..d0f0a8b 100644 --- a/entry.go +++ b/entry.go @@ -216,6 +216,7 @@ func CommitEntry(e *Entry, ec *ECAddress) (string, error) { if err != nil { return "", err } + if resp.Error != nil { return "", resp.Error } diff --git a/wsapistructs.go b/wsapistructs.go index 8093577..8415919 100644 --- a/wsapistructs.go +++ b/wsapistructs.go @@ -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"` }