wao 0.10.6 → 0.10.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/cjs/ao.js +158 -154
  2. package/esm/ao.js +32 -28
  3. package/package.json +2 -1
package/cjs/ao.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports["default"] = void 0;
7
7
  var WarpArBundles = _interopRequireWildcard(require("warp-arbundles"));
8
8
  var _ar4 = _interopRequireDefault(require("./ar.js"));
9
+ var _md = _interopRequireDefault(require("md5"));
9
10
  var _aoconnect = require("@permaweb/aoconnect");
10
11
  var _ramda = require("ramda");
11
12
  var _utils = require("./utils.js");
@@ -613,11 +614,11 @@ var AO = /*#__PURE__*/function () {
613
614
  value: function () {
614
615
  var _msg = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref12) {
615
616
  var _this3 = this;
616
- var pid, jwk, data, _ref12$act, act, _ref12$tags, tags, _ref12$check, check, get, _ref12$timeout, timeout, _ref12$mode, mode, err, _yield$this$ar$checkW2, anchors, getNewTxs, checkOut, res, out, mid, results, _tags, start, _txs, _txmap, t, checked, _iterator6, _step6, v, _res;
617
+ var pid, jwk, data, _ref12$act, act, _ref12$tags, tags, _ref12$check, check, get, _ref12$timeout, timeout, _ref12$mode, mode, _ref12$limit, limit, err, _yield$this$ar$checkW2, anchors, hash, mid, getNewTxs, checkOut, res, out, results, _tags, start, _txs, _txmap, checked, _iterator5, _step5, v, _res;
617
618
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
618
619
  while (1) switch (_context11.prev = _context11.next) {
619
620
  case 0:
620
- pid = _ref12.pid, jwk = _ref12.jwk, data = _ref12.data, _ref12$act = _ref12.act, act = _ref12$act === void 0 ? "Eval" : _ref12$act, _ref12$tags = _ref12.tags, tags = _ref12$tags === void 0 ? {} : _ref12$tags, _ref12$check = _ref12.check, check = _ref12$check === void 0 ? [] : _ref12$check, get = _ref12.get, _ref12$timeout = _ref12.timeout, timeout = _ref12$timeout === void 0 ? 0 : _ref12$timeout, _ref12$mode = _ref12.mode, mode = _ref12$mode === void 0 ? "aoconnect" : _ref12$mode;
621
+ pid = _ref12.pid, jwk = _ref12.jwk, data = _ref12.data, _ref12$act = _ref12.act, act = _ref12$act === void 0 ? "Eval" : _ref12$act, _ref12$tags = _ref12.tags, tags = _ref12$tags === void 0 ? {} : _ref12$tags, _ref12$check = _ref12.check, check = _ref12$check === void 0 ? [] : _ref12$check, get = _ref12.get, _ref12$timeout = _ref12.timeout, timeout = _ref12$timeout === void 0 ? 0 : _ref12$timeout, _ref12$mode = _ref12.mode, mode = _ref12$mode === void 0 ? "aoconnect" : _ref12$mode, _ref12$limit = _ref12.limit, limit = _ref12$limit === void 0 ? 25 : _ref12$limit;
621
622
  err = null;
622
623
  _context11.next = 4;
623
624
  return this.ar.checkWallet({
@@ -636,38 +637,44 @@ var AO = /*#__PURE__*/function () {
636
637
  });
637
638
  case 9:
638
639
  anchors = {};
640
+ hash = null;
641
+ mid = null;
639
642
  getNewTxs = /*#__PURE__*/function () {
640
643
  var _ref13 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(pid, _txs, _txmap) {
641
- var txs, _iterator2, _step2, v, t, _t$fromProcess, _v$owner, _iterator3, _step3, _v, _iterator4, _step4, v2;
644
+ var exists, txs, _iterator2, _step2, v, t, _t$fromProcess, _v$owner, _iterator3, _step3, _v, hash2;
642
645
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
643
646
  while (1) switch (_context9.prev = _context9.next) {
644
647
  case 0:
648
+ exists = false;
645
649
  if (!(mode === "gql")) {
646
- _context9.next = 8;
650
+ _context9.next = 9;
647
651
  break;
648
652
  }
649
- _context9.next = 3;
653
+ _context9.next = 4;
650
654
  return _this3.ar.gql.txs({
651
655
  recipient: pid,
656
+ limit: limit,
652
657
  fields: ["id", "recipient", "tags", {
653
658
  owner: ["address"]
654
659
  }]
655
660
  });
656
- case 3:
661
+ case 4:
657
662
  txs = _context9.sent;
658
- _iterator2 = _createForOfIteratorHelper(txs);
663
+ _iterator2 = _createForOfIteratorHelper((0, _ramda.reverse)(txs));
659
664
  try {
660
665
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
661
666
  v = _step2.value;
662
- if ((0, _ramda.isNil)(_txmap[v.id])) {
663
- t = (0, _utils.ltags)(v.tags);
664
- if (t.type === "Message") {
665
- v.from = (_t$fromProcess = t["from-process"]) !== null && _t$fromProcess !== void 0 ? _t$fromProcess : (_v$owner = v.owner) === null || _v$owner === void 0 ? void 0 : _v$owner.address;
666
- _txs.unshift(v);
667
- _txmap[v.id] = {
668
- checked: false,
669
- ref: t["x-reference"]
670
- };
667
+ if (v.id === mid) exists = true;else if (exists) {
668
+ if ((0, _ramda.isNil)(_txmap[v.id])) {
669
+ t = (0, _utils.ltags)(v.tags);
670
+ if (t.type === "Message") {
671
+ v.from = (_t$fromProcess = t["from-process"]) !== null && _t$fromProcess !== void 0 ? _t$fromProcess : (_v$owner = v.owner) === null || _v$owner === void 0 ? void 0 : _v$owner.address;
672
+ _txs.unshift(v);
673
+ _txmap[v.id] = {
674
+ checked: false,
675
+ ref: t["x-reference"]
676
+ };
677
+ }
671
678
  }
672
679
  }
673
680
  }
@@ -676,41 +683,35 @@ var AO = /*#__PURE__*/function () {
676
683
  } finally {
677
684
  _iterator2.f();
678
685
  }
679
- _context9.next = 16;
686
+ _context9.next = 17;
680
687
  break;
681
- case 8:
688
+ case 9:
682
689
  _context9.t0 = _createForOfIteratorHelper;
683
690
  _context9.t1 = _ramda.reverse;
684
- _context9.next = 12;
691
+ _context9.next = 13;
685
692
  return _this3.res({
686
- pid: pid
693
+ pid: pid,
694
+ limit: limit
687
695
  });
688
- case 12:
696
+ case 13:
689
697
  _context9.t2 = _context9.sent;
690
698
  _context9.t3 = (0, _context9.t1)(_context9.t2);
691
699
  _iterator3 = (0, _context9.t0)(_context9.t3);
692
700
  try {
693
701
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
694
702
  _v = _step3.value;
695
- if ((0, _ramda.isNil)(_txmap[_v.cursor])) {
696
- _txmap[_v.cursor] = {
697
- checked: false,
698
- res: _v
699
- };
700
- _txs.unshift({
701
- id: _v.cursor
702
- });
703
- console.log("new shit is here", _v.cursor, _v);
704
- _iterator4 = _createForOfIteratorHelper(_v.Messages || []);
705
- try {
706
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
707
- v2 = _step4.value;
708
- console.log(v2);
709
- }
710
- } catch (err) {
711
- _iterator4.e(err);
712
- } finally {
713
- _iterator4.f();
703
+ hash2 = (0, _md["default"])(JSON.stringify((0, _ramda.dissoc)("cursor", _v)));
704
+ if (!exists) {
705
+ if (hash2 === hash) exists = true;
706
+ } else {
707
+ if ((0, _ramda.isNil)(_txmap[_v.cursor + pid])) {
708
+ _txmap[_v.cursor + pid] = {
709
+ checked: false,
710
+ res: _v
711
+ };
712
+ _txs.unshift({
713
+ id: _v.cursor + pid
714
+ });
714
715
  }
715
716
  }
716
717
  }
@@ -719,7 +720,7 @@ var AO = /*#__PURE__*/function () {
719
720
  } finally {
720
721
  _iterator3.f();
721
722
  }
722
- case 16:
723
+ case 17:
723
724
  case "end":
724
725
  return _context9.stop();
725
726
  }
@@ -731,21 +732,21 @@ var AO = /*#__PURE__*/function () {
731
732
  }();
732
733
  checkOut = /*#__PURE__*/function () {
733
734
  var _ref14 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(get, _txs, _txmap, out) {
734
- var _iterator5, _step5, v, _res2, _out;
735
+ var _iterator4, _step4, v, _res2, _out;
735
736
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
736
737
  while (1) switch (_context10.prev = _context10.next) {
737
738
  case 0:
738
- _iterator5 = _createForOfIteratorHelper(_txs);
739
+ _iterator4 = _createForOfIteratorHelper(_txs);
739
740
  _context10.prev = 1;
740
- _iterator5.s();
741
+ _iterator4.s();
741
742
  case 3:
742
- if ((_step5 = _iterator5.n()).done) {
743
- _context10.next = 18;
743
+ if ((_step4 = _iterator4.n()).done) {
744
+ _context10.next = 19;
744
745
  break;
745
746
  }
746
- v = _step5.value;
747
+ v = _step4.value;
747
748
  if (!(0, _ramda.isNil)(_txmap[v.id].res)) {
748
- _context10.next = 10;
749
+ _context10.next = 11;
749
750
  break;
750
751
  }
751
752
  _context10.next = 8;
@@ -755,210 +756,213 @@ var AO = /*#__PURE__*/function () {
755
756
  });
756
757
  case 8:
757
758
  _res2 = _context10.sent;
759
+ if (!hash) console.log(_res2);
758
760
  _txmap[v.id].res = _res2;
759
- case 10:
761
+ case 11:
760
762
  if (!(!(0, _ramda.isNil)(_txmap[v.id].res) && _txmap[v.id].out !== true)) {
761
- _context10.next = 16;
763
+ _context10.next = 17;
762
764
  break;
763
765
  }
764
766
  _txmap[v.id].out = true;
765
767
  _out = (0, _utils.getTagVal)(get, _txmap[v.id].res, v.from);
766
768
  out = (0, _utils.mergeOut)(out, _out, get);
767
769
  if (!(0, _utils.isOutComplete)(out, get)) {
768
- _context10.next = 16;
770
+ _context10.next = 17;
769
771
  break;
770
772
  }
771
- return _context10.abrupt("break", 18);
772
- case 16:
773
+ return _context10.abrupt("break", 19);
774
+ case 17:
773
775
  _context10.next = 3;
774
776
  break;
775
- case 18:
776
- _context10.next = 23;
777
+ case 19:
778
+ _context10.next = 24;
777
779
  break;
778
- case 20:
779
- _context10.prev = 20;
780
+ case 21:
781
+ _context10.prev = 21;
780
782
  _context10.t0 = _context10["catch"](1);
781
- _iterator5.e(_context10.t0);
782
- case 23:
783
- _context10.prev = 23;
784
- _iterator5.f();
785
- return _context10.finish(23);
786
- case 26:
787
- return _context10.abrupt("return", out);
783
+ _iterator4.e(_context10.t0);
784
+ case 24:
785
+ _context10.prev = 24;
786
+ _iterator4.f();
787
+ return _context10.finish(24);
788
788
  case 27:
789
+ return _context10.abrupt("return", out);
790
+ case 28:
789
791
  case "end":
790
792
  return _context10.stop();
791
793
  }
792
- }, _callee10, null, [[1, 20, 23, 26]]);
794
+ }, _callee10, null, [[1, 21, 24, 27]]);
793
795
  }));
794
796
  return function checkOut(_x11, _x12, _x13, _x14) {
795
797
  return _ref14.apply(this, arguments);
796
798
  };
797
799
  }();
798
- res = null, out = null, mid = null, results = [];
800
+ res = null, out = null, results = [];
799
801
  _tags = (0, _utils.buildTags)(act, tags);
800
802
  start = Date.now();
801
- _context11.prev = 15;
802
- _context11.next = 18;
803
+ _context11.prev = 17;
804
+ _context11.next = 20;
803
805
  return this.message({
804
806
  process: pid,
805
807
  signer: this.toSigner(jwk),
806
808
  tags: _tags,
807
809
  data: (0, _utils.jsonToStr)(data)
808
810
  });
809
- case 18:
811
+ case 20:
810
812
  mid = _context11.sent;
811
813
  if (!(0, _ramda.is)(Array, check)) check = [check];
812
814
  _context11.t0 = mid;
813
- _context11.next = 23;
815
+ _context11.next = 25;
814
816
  return this.ar.toAddr(jwk);
815
- case 23:
817
+ case 25:
816
818
  _context11.t1 = _context11.sent;
817
819
  _context11.t2 = {
818
820
  id: _context11.t0,
819
821
  from: _context11.t1
820
822
  };
821
823
  _txs = [_context11.t2];
822
- _txmap = {};
823
- t = (0, _utils.ltags)(_tags);
824
- checked = false;
825
- _txmap[mid] = {
826
- checked: false,
827
- ref: t["x-reference"]
828
- };
824
+ _context11.next = 30;
825
+ return this.res({
826
+ pid: pid,
827
+ mid: mid
828
+ });
829
829
  case 30:
830
- _iterator6 = _createForOfIteratorHelper(_txs);
831
- _context11.prev = 31;
832
- _iterator6.s();
833
- case 33:
834
- if ((_step6 = _iterator6.n()).done) {
835
- _context11.next = 48;
830
+ res = _context11.sent;
831
+ hash = (0, _md["default"])(JSON.stringify(res));
832
+ _txmap = _defineProperty({}, mid, {
833
+ checked: false,
834
+ res: res
835
+ });
836
+ results.push({
837
+ mid: mid,
838
+ res: res
839
+ });
840
+ checked = false;
841
+ case 35:
842
+ _iterator5 = _createForOfIteratorHelper(_txs);
843
+ _context11.prev = 36;
844
+ _iterator5.s();
845
+ case 38:
846
+ if ((_step5 = _iterator5.n()).done) {
847
+ _context11.next = 52;
836
848
  break;
837
849
  }
838
- v = _step6.value;
850
+ v = _step5.value;
839
851
  if (_txmap[v.id].checked) {
840
- _context11.next = 46;
852
+ _context11.next = 50;
841
853
  break;
842
854
  }
843
855
  _txmap[v.id].checked = true;
844
856
  if (!(0, _ramda.isNil)(_txmap[v.id].res)) {
845
- _context11.next = 43;
857
+ _context11.next = 47;
846
858
  break;
847
859
  }
848
- _context11.next = 40;
860
+ _context11.next = 45;
849
861
  return this.res({
850
862
  pid: pid,
851
863
  mid: v.id
852
864
  });
853
- case 40:
865
+ case 45:
854
866
  _res = _context11.sent;
855
- if ((0, _ramda.isNil)(res)) {
856
- res = _res;
857
- mid = v.id;
858
- results.push({
859
- mid: mid,
860
- res: res
861
- });
862
- }
863
867
  _txmap[v.id].res = _res;
864
- case 43:
868
+ case 47:
865
869
  if (!(0, _ramda.isNil)(check) && check.length > 0) {
866
870
  checked = (0, _utils.allChecked)(check, _txmap[v.id].res, v.from);
867
871
  } else {
868
872
  checked = true;
869
873
  }
870
874
  if (!checked) {
871
- _context11.next = 46;
875
+ _context11.next = 50;
872
876
  break;
873
877
  }
874
- return _context11.abrupt("break", 48);
875
- case 46:
876
- _context11.next = 33;
878
+ return _context11.abrupt("break", 52);
879
+ case 50:
880
+ _context11.next = 38;
877
881
  break;
878
- case 48:
879
- _context11.next = 53;
882
+ case 52:
883
+ _context11.next = 57;
880
884
  break;
881
- case 50:
882
- _context11.prev = 50;
883
- _context11.t3 = _context11["catch"](31);
884
- _iterator6.e(_context11.t3);
885
- case 53:
886
- _context11.prev = 53;
887
- _iterator6.f();
888
- return _context11.finish(53);
889
- case 56:
885
+ case 54:
886
+ _context11.prev = 54;
887
+ _context11.t3 = _context11["catch"](36);
888
+ _iterator5.e(_context11.t3);
889
+ case 57:
890
+ _context11.prev = 57;
891
+ _iterator5.f();
892
+ return _context11.finish(57);
893
+ case 60:
890
894
  if (!checked) {
891
- _context11.next = 58;
895
+ _context11.next = 62;
892
896
  break;
893
897
  }
894
- return _context11.abrupt("break", 63);
895
- case 58:
896
- _context11.next = 60;
898
+ return _context11.abrupt("break", 67);
899
+ case 62:
900
+ _context11.next = 64;
897
901
  return (0, _utils.wait)(1000);
898
- case 60:
899
- _context11.next = 62;
902
+ case 64:
903
+ _context11.next = 66;
900
904
  return getNewTxs(pid, _txs, _txmap);
901
- case 62:
905
+ case 66:
902
906
  if (Date.now() - start < timeout) {
903
- _context11.next = 30;
907
+ _context11.next = 35;
904
908
  break;
905
909
  }
906
- case 63:
910
+ case 67:
907
911
  if (checked) {
908
- _context11.next = 67;
912
+ _context11.next = 71;
909
913
  break;
910
914
  }
911
915
  err = "something went wrong!";
912
- _context11.next = 91;
916
+ _context11.next = 95;
913
917
  break;
914
- case 67:
918
+ case 71:
915
919
  _context11.t4 = _utils.mergeOut;
916
920
  _context11.t5 = out;
917
- _context11.next = 71;
921
+ _context11.next = 75;
918
922
  return checkOut(get, _txs, _txmap, out);
919
- case 71:
923
+ case 75:
920
924
  _context11.t6 = _context11.sent;
921
925
  _context11.t7 = get;
922
926
  out = (0, _context11.t4)(_context11.t5, _context11.t6, _context11.t7);
923
927
  if (!(!(0, _utils.isOutComplete)(out, get) && !(0, _ramda.isNil)(get))) {
924
- _context11.next = 91;
928
+ _context11.next = 95;
925
929
  break;
926
930
  }
927
- case 75:
931
+ case 79:
928
932
  if (!(Date.now() - start < timeout)) {
929
- _context11.next = 91;
933
+ _context11.next = 95;
930
934
  break;
931
935
  }
932
- _context11.next = 78;
936
+ _context11.next = 82;
933
937
  return getNewTxs(pid, _txs, _txmap);
934
- case 78:
938
+ case 82:
935
939
  _context11.t8 = _utils.mergeOut;
936
940
  _context11.t9 = out;
937
- _context11.next = 82;
941
+ _context11.next = 86;
938
942
  return checkOut(get, _txs, _txmap, out);
939
- case 82:
943
+ case 86:
940
944
  _context11.t10 = _context11.sent;
941
945
  _context11.t11 = get;
942
946
  out = (0, _context11.t8)(_context11.t9, _context11.t10, _context11.t11);
943
947
  if (!(0, _utils.isOutComplete)(out, get)) {
944
- _context11.next = 87;
948
+ _context11.next = 91;
945
949
  break;
946
950
  }
947
- return _context11.abrupt("break", 91);
948
- case 87:
949
- _context11.next = 89;
951
+ return _context11.abrupt("break", 95);
952
+ case 91:
953
+ _context11.next = 93;
950
954
  return (0, _utils.wait)(1000);
951
- case 89:
952
- _context11.next = 75;
955
+ case 93:
956
+ _context11.next = 79;
953
957
  break;
954
- case 91:
955
- _context11.next = 96;
958
+ case 95:
959
+ _context11.next = 100;
956
960
  break;
957
- case 93:
958
- _context11.prev = 93;
959
- _context11.t12 = _context11["catch"](15);
961
+ case 97:
962
+ _context11.prev = 97;
963
+ _context11.t12 = _context11["catch"](17);
960
964
  err = _context11.t12;
961
- case 96:
965
+ case 100:
962
966
  return _context11.abrupt("return", {
963
967
  mid: mid,
964
968
  res: res,
@@ -966,11 +970,11 @@ var AO = /*#__PURE__*/function () {
966
970
  out: out,
967
971
  results: results
968
972
  });
969
- case 97:
973
+ case 101:
970
974
  case "end":
971
975
  return _context11.stop();
972
976
  }
973
- }, _callee11, this, [[15, 93], [31, 50, 53, 56]]);
977
+ }, _callee11, this, [[17, 97], [36, 54, 57, 60]]);
974
978
  }));
975
979
  function msg(_x7) {
976
980
  return _msg.apply(this, arguments);
@@ -1433,7 +1437,7 @@ var AO = /*#__PURE__*/function () {
1433
1437
  key: "deploy",
1434
1438
  value: function () {
1435
1439
  var _deploy = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee21(_ref25) {
1436
- var boot, loads, src, src_data, _ref25$fills, fills, _ref25$module, module, _ref25$scheduler, scheduler, jwk, _ref25$tags, tags, data, fns, isBoot, i, _iterator7, _step7, v, args, result;
1440
+ var boot, loads, src, src_data, _ref25$fills, fills, _ref25$module, module, _ref25$scheduler, scheduler, jwk, _ref25$tags, tags, data, fns, isBoot, i, _iterator6, _step6, v, args, result;
1437
1441
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1438
1442
  while (1) switch (_context21.prev = _context21.next) {
1439
1443
  case 0:
@@ -1485,14 +1489,14 @@ var AO = /*#__PURE__*/function () {
1485
1489
  }
1486
1490
  });
1487
1491
  i = 0;
1488
- _iterator7 = _createForOfIteratorHelper(!loads ? src_data ? [{
1492
+ _iterator6 = _createForOfIteratorHelper(!loads ? src_data ? [{
1489
1493
  data: src_data,
1490
1494
  src: src,
1491
1495
  fills: fills
1492
1496
  }] : [] : loads);
1493
1497
  try {
1494
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1495
- v = _step7.value;
1498
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1499
+ v = _step6.value;
1496
1500
  if (!isBoot || i !== 0) {
1497
1501
  args = v;
1498
1502
  if (typeof args === "string") args = {
@@ -1509,9 +1513,9 @@ var AO = /*#__PURE__*/function () {
1509
1513
  i++;
1510
1514
  }
1511
1515
  } catch (err) {
1512
- _iterator7.e(err);
1516
+ _iterator6.e(err);
1513
1517
  } finally {
1514
- _iterator7.f();
1518
+ _iterator6.f();
1515
1519
  }
1516
1520
  _context21.next = 9;
1517
1521
  return this.pipe({
package/esm/ao.js CHANGED
@@ -2,7 +2,7 @@ import * as WarpArBundles from "warp-arbundles"
2
2
  const pkg = WarpArBundles.default ?? WarpArBundles
3
3
  const { createData, ArweaveSigner } = pkg
4
4
  import AR from "./ar.js"
5
-
5
+ import md5 from "md5"
6
6
  import {
7
7
  createDataItemSigner,
8
8
  connect,
@@ -17,6 +17,7 @@ import {
17
17
  } from "@permaweb/aoconnect"
18
18
 
19
19
  import {
20
+ dissoc,
20
21
  equals,
21
22
  concat,
22
23
  is,
@@ -57,10 +58,7 @@ function createDataItemSigner2(wallet) {
57
58
  const signer = new ArweaveSigner(wallet)
58
59
  const dataItem = createData(data, signer, { tags, target, anchor })
59
60
  const sig = dataItem.sign(signer).then(async () => {
60
- return {
61
- id: await dataItem.id,
62
- raw: await dataItem.getRaw(),
63
- }
61
+ return { id: await dataItem.id, raw: await dataItem.getRaw() }
64
62
  })
65
63
  return sig
66
64
  }
@@ -386,35 +384,44 @@ class AO {
386
384
  get,
387
385
  timeout = 0,
388
386
  mode = "aoconnect",
387
+ limit = 25,
389
388
  }) {
390
389
  let err = null
391
390
  ;({ jwk, err } = await this.ar.checkWallet({ jwk }))
392
391
  if (err) return { err }
393
392
  let anchors = {}
393
+ let hash = null
394
+ let mid = null
394
395
  const getNewTxs = async (pid, _txs, _txmap) => {
396
+ let exists = false
395
397
  if (mode === "gql") {
396
398
  const txs = await this.ar.gql.txs({
397
399
  recipient: pid,
400
+ limit,
398
401
  fields: ["id", "recipient", "tags", { owner: ["address"] }],
399
402
  })
400
- for (const v of txs) {
401
- if (isNil(_txmap[v.id])) {
402
- const t = ltags(v.tags)
403
- if (t.type === "Message") {
404
- v.from = t["from-process"] ?? v.owner?.address
405
- _txs.unshift(v)
406
- _txmap[v.id] = { checked: false, ref: t["x-reference"] }
403
+ for (const v of reverse(txs)) {
404
+ if (v.id === mid) exists = true
405
+ else if (exists) {
406
+ if (isNil(_txmap[v.id])) {
407
+ const t = ltags(v.tags)
408
+ if (t.type === "Message") {
409
+ v.from = t["from-process"] ?? v.owner?.address
410
+ _txs.unshift(v)
411
+ _txmap[v.id] = { checked: false, ref: t["x-reference"] }
412
+ }
407
413
  }
408
414
  }
409
415
  }
410
416
  } else {
411
- for (let v of reverse(await this.res({ pid }))) {
412
- if (isNil(_txmap[v.cursor])) {
413
- _txmap[v.cursor] = { checked: false, res: v }
414
- _txs.unshift({ id: v.cursor })
415
- console.log("new shit is here", v.cursor, v)
416
- for (let v2 of v.Messages || []) {
417
- console.log(v2)
417
+ for (let v of reverse(await this.res({ pid, limit }))) {
418
+ const hash2 = md5(JSON.stringify(dissoc("cursor", v)))
419
+ if (!exists) {
420
+ if (hash2 === hash) exists = true
421
+ } else {
422
+ if (isNil(_txmap[v.cursor + pid])) {
423
+ _txmap[v.cursor + pid] = { checked: false, res: v }
424
+ _txs.unshift({ id: v.cursor + pid })
418
425
  }
419
426
  }
420
427
  }
@@ -424,6 +431,7 @@ class AO {
424
431
  for (let v of _txs) {
425
432
  if (isNil(_txmap[v.id].res)) {
426
433
  const res = await this.res({ pid, mid: v.id })
434
+ if (!hash) console.log(res)
427
435
  _txmap[v.id].res = res
428
436
  }
429
437
  if (!isNil(_txmap[v.id].res) && _txmap[v.id].out !== true) {
@@ -435,7 +443,7 @@ class AO {
435
443
  }
436
444
  return out
437
445
  }
438
- let [res, out, mid, results] = [null, null, null, []]
446
+ let [res, out, results] = [null, null, []]
439
447
  let _tags = buildTags(act, tags)
440
448
  let start = Date.now()
441
449
  try {
@@ -447,21 +455,17 @@ class AO {
447
455
  })
448
456
  if (!is(Array, check)) check = [check]
449
457
  let _txs = [{ id: mid, from: await this.ar.toAddr(jwk) }]
450
- let _txmap = {}
451
- const t = ltags(_tags)
458
+ res = await this.res({ pid, mid })
459
+ hash = md5(JSON.stringify(res))
460
+ let _txmap = { [mid]: { checked: false, res } }
461
+ results.push({ mid, res })
452
462
  let checked = false
453
- _txmap[mid] = { checked: false, ref: t["x-reference"] }
454
463
  do {
455
464
  for (let v of _txs) {
456
465
  if (!_txmap[v.id].checked) {
457
466
  _txmap[v.id].checked = true
458
467
  if (isNil(_txmap[v.id].res)) {
459
468
  const _res = await this.res({ pid, mid: v.id })
460
- if (isNil(res)) {
461
- res = _res
462
- mid = v.id
463
- results.push({ mid, res })
464
- }
465
469
  _txmap[v.id].res = _res
466
470
  }
467
471
  if (!isNil(check) && check.length > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wao",
3
- "version": "0.10.6",
3
+ "version": "0.10.7",
4
4
  "bin": {
5
5
  "wao": "./cjs/cli.js",
6
6
  "wao-esm": "./esm/cli.js"
@@ -41,6 +41,7 @@
41
41
  "lmdb": "^3.2.2",
42
42
  "localforage": "^1.10.0",
43
43
  "lz4-asm": "^0.4.2",
44
+ "md5": "^2.3.0",
44
45
  "pm2": "^5.4.3",
45
46
  "ramda": "^0.30.1",
46
47
  "wasm-brotli": "^2.0.2",