diff --git a/src/boc/Cell.js b/src/boc/Cell.js index 31d46444..e54ae1f4 100644 --- a/src/boc/Cell.js +++ b/src/boc/Cell.js @@ -21,6 +21,27 @@ class Cell { this.isExotic = false; } + /** + * @return {number} + */ + get max_refs() { + return 4; + } + + /** + * @return {number} + */ + getFreeRefs() { + return this.max_refs - this.refs.length; + } + + /** + * @return {number} + */ + getUsedRefs() { + return this.refs.length; + } + /** * @param serializedBoc {string | Uint8Array} hex or bytearray * @return {Cell[]} root cells diff --git a/src/contract/index.js b/src/contract/index.js index fd3a5e95..40411f5d 100644 --- a/src/contract/index.js +++ b/src/contract/index.js @@ -197,9 +197,12 @@ class Contract { } else { commonMsgInfo.bits.writeBit(false); } - // TODO we also should check for free refs here + if (body) { - if (commonMsgInfo.bits.getFreeBits() >= body.bits.getUsedBits()) { + if ( + commonMsgInfo.bits.getFreeBits() >= body.bits.getUsedBits() && + commonMsgInfo.getFreeRefs() >= body.getUsedRefs() + ) { commonMsgInfo.bits.writeBit(false); commonMsgInfo.writeCell(body); } else {