wao 0.10.6 → 0.10.8

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 +166 -154
  2. package/esm/ao.js +41 -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");
@@ -31,6 +32,14 @@ function _asyncToGenerator(n) { return function () { var t = this, e = arguments
31
32
  var pkg = (_WarpArBundles$defaul = WarpArBundles["default"]) !== null && _WarpArBundles$defaul !== void 0 ? _WarpArBundles$defaul : WarpArBundles;
32
33
  var createData = pkg.createData,
33
34
  ArweaveSigner = pkg.ArweaveSigner;
35
+ var getHash = function getHash(res) {
36
+ var _res$Messages, _res$Spawns, _res$Assignments;
37
+ return (0, _md["default"])(JSON.stringify({
38
+ Messages: (_res$Messages = res.Messages) !== null && _res$Messages !== void 0 ? _res$Messages : [],
39
+ Spawns: (_res$Spawns = res.Spawns) !== null && _res$Spawns !== void 0 ? _res$Spawns : [],
40
+ Assignments: (_res$Assignments = res.Assignments) !== null && _res$Assignments !== void 0 ? _res$Assignments : []
41
+ }));
42
+ };
34
43
  function createDataItemSigner2(wallet) {
35
44
  var signer = /*#__PURE__*/function () {
36
45
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
@@ -613,11 +622,11 @@ var AO = /*#__PURE__*/function () {
613
622
  value: function () {
614
623
  var _msg = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(_ref12) {
615
624
  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;
625
+ 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
626
  return _regeneratorRuntime().wrap(function _callee11$(_context11) {
618
627
  while (1) switch (_context11.prev = _context11.next) {
619
628
  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;
629
+ 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
630
  err = null;
622
631
  _context11.next = 4;
623
632
  return this.ar.checkWallet({
@@ -636,38 +645,44 @@ var AO = /*#__PURE__*/function () {
636
645
  });
637
646
  case 9:
638
647
  anchors = {};
648
+ hash = null;
649
+ mid = null;
639
650
  getNewTxs = /*#__PURE__*/function () {
640
651
  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;
652
+ var exists, txs, _iterator2, _step2, v, t, _t$fromProcess, _v$owner, _iterator3, _step3, _v, hash2;
642
653
  return _regeneratorRuntime().wrap(function _callee9$(_context9) {
643
654
  while (1) switch (_context9.prev = _context9.next) {
644
655
  case 0:
656
+ exists = false;
645
657
  if (!(mode === "gql")) {
646
- _context9.next = 8;
658
+ _context9.next = 9;
647
659
  break;
648
660
  }
649
- _context9.next = 3;
661
+ _context9.next = 4;
650
662
  return _this3.ar.gql.txs({
651
663
  recipient: pid,
664
+ limit: limit,
652
665
  fields: ["id", "recipient", "tags", {
653
666
  owner: ["address"]
654
667
  }]
655
668
  });
656
- case 3:
669
+ case 4:
657
670
  txs = _context9.sent;
658
- _iterator2 = _createForOfIteratorHelper(txs);
671
+ _iterator2 = _createForOfIteratorHelper((0, _ramda.reverse)(txs));
659
672
  try {
660
673
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
661
674
  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
- };
675
+ if (v.id === mid) exists = true;else if (exists) {
676
+ if ((0, _ramda.isNil)(_txmap[v.id])) {
677
+ t = (0, _utils.ltags)(v.tags);
678
+ if (t.type === "Message") {
679
+ 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;
680
+ _txs.unshift(v);
681
+ _txmap[v.id] = {
682
+ checked: false,
683
+ ref: t["x-reference"]
684
+ };
685
+ }
671
686
  }
672
687
  }
673
688
  }
@@ -676,41 +691,35 @@ var AO = /*#__PURE__*/function () {
676
691
  } finally {
677
692
  _iterator2.f();
678
693
  }
679
- _context9.next = 16;
694
+ _context9.next = 17;
680
695
  break;
681
- case 8:
696
+ case 9:
682
697
  _context9.t0 = _createForOfIteratorHelper;
683
698
  _context9.t1 = _ramda.reverse;
684
- _context9.next = 12;
699
+ _context9.next = 13;
685
700
  return _this3.res({
686
- pid: pid
701
+ pid: pid,
702
+ limit: limit
687
703
  });
688
- case 12:
704
+ case 13:
689
705
  _context9.t2 = _context9.sent;
690
706
  _context9.t3 = (0, _context9.t1)(_context9.t2);
691
707
  _iterator3 = (0, _context9.t0)(_context9.t3);
692
708
  try {
693
709
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
694
710
  _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();
711
+ hash2 = getHash(_v);
712
+ if (!exists) {
713
+ if (hash2 === hash) exists = true;
714
+ } else {
715
+ if ((0, _ramda.isNil)(_txmap[_v.cursor + pid])) {
716
+ _txmap[_v.cursor + pid] = {
717
+ checked: false,
718
+ res: _v
719
+ };
720
+ _txs.unshift({
721
+ id: _v.cursor + pid
722
+ });
714
723
  }
715
724
  }
716
725
  }
@@ -719,7 +728,7 @@ var AO = /*#__PURE__*/function () {
719
728
  } finally {
720
729
  _iterator3.f();
721
730
  }
722
- case 16:
731
+ case 17:
723
732
  case "end":
724
733
  return _context9.stop();
725
734
  }
@@ -731,21 +740,21 @@ var AO = /*#__PURE__*/function () {
731
740
  }();
732
741
  checkOut = /*#__PURE__*/function () {
733
742
  var _ref14 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(get, _txs, _txmap, out) {
734
- var _iterator5, _step5, v, _res2, _out;
743
+ var _iterator4, _step4, v, _res2, _out;
735
744
  return _regeneratorRuntime().wrap(function _callee10$(_context10) {
736
745
  while (1) switch (_context10.prev = _context10.next) {
737
746
  case 0:
738
- _iterator5 = _createForOfIteratorHelper(_txs);
747
+ _iterator4 = _createForOfIteratorHelper(_txs);
739
748
  _context10.prev = 1;
740
- _iterator5.s();
749
+ _iterator4.s();
741
750
  case 3:
742
- if ((_step5 = _iterator5.n()).done) {
743
- _context10.next = 18;
751
+ if ((_step4 = _iterator4.n()).done) {
752
+ _context10.next = 19;
744
753
  break;
745
754
  }
746
- v = _step5.value;
755
+ v = _step4.value;
747
756
  if (!(0, _ramda.isNil)(_txmap[v.id].res)) {
748
- _context10.next = 10;
757
+ _context10.next = 11;
749
758
  break;
750
759
  }
751
760
  _context10.next = 8;
@@ -755,210 +764,213 @@ var AO = /*#__PURE__*/function () {
755
764
  });
756
765
  case 8:
757
766
  _res2 = _context10.sent;
767
+ if (!hash) console.log(_res2);
758
768
  _txmap[v.id].res = _res2;
759
- case 10:
769
+ case 11:
760
770
  if (!(!(0, _ramda.isNil)(_txmap[v.id].res) && _txmap[v.id].out !== true)) {
761
- _context10.next = 16;
771
+ _context10.next = 17;
762
772
  break;
763
773
  }
764
774
  _txmap[v.id].out = true;
765
775
  _out = (0, _utils.getTagVal)(get, _txmap[v.id].res, v.from);
766
776
  out = (0, _utils.mergeOut)(out, _out, get);
767
777
  if (!(0, _utils.isOutComplete)(out, get)) {
768
- _context10.next = 16;
778
+ _context10.next = 17;
769
779
  break;
770
780
  }
771
- return _context10.abrupt("break", 18);
772
- case 16:
781
+ return _context10.abrupt("break", 19);
782
+ case 17:
773
783
  _context10.next = 3;
774
784
  break;
775
- case 18:
776
- _context10.next = 23;
785
+ case 19:
786
+ _context10.next = 24;
777
787
  break;
778
- case 20:
779
- _context10.prev = 20;
788
+ case 21:
789
+ _context10.prev = 21;
780
790
  _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);
791
+ _iterator4.e(_context10.t0);
792
+ case 24:
793
+ _context10.prev = 24;
794
+ _iterator4.f();
795
+ return _context10.finish(24);
788
796
  case 27:
797
+ return _context10.abrupt("return", out);
798
+ case 28:
789
799
  case "end":
790
800
  return _context10.stop();
791
801
  }
792
- }, _callee10, null, [[1, 20, 23, 26]]);
802
+ }, _callee10, null, [[1, 21, 24, 27]]);
793
803
  }));
794
804
  return function checkOut(_x11, _x12, _x13, _x14) {
795
805
  return _ref14.apply(this, arguments);
796
806
  };
797
807
  }();
798
- res = null, out = null, mid = null, results = [];
808
+ res = null, out = null, results = [];
799
809
  _tags = (0, _utils.buildTags)(act, tags);
800
810
  start = Date.now();
801
- _context11.prev = 15;
802
- _context11.next = 18;
811
+ _context11.prev = 17;
812
+ _context11.next = 20;
803
813
  return this.message({
804
814
  process: pid,
805
815
  signer: this.toSigner(jwk),
806
816
  tags: _tags,
807
817
  data: (0, _utils.jsonToStr)(data)
808
818
  });
809
- case 18:
819
+ case 20:
810
820
  mid = _context11.sent;
811
821
  if (!(0, _ramda.is)(Array, check)) check = [check];
812
822
  _context11.t0 = mid;
813
- _context11.next = 23;
823
+ _context11.next = 25;
814
824
  return this.ar.toAddr(jwk);
815
- case 23:
825
+ case 25:
816
826
  _context11.t1 = _context11.sent;
817
827
  _context11.t2 = {
818
828
  id: _context11.t0,
819
829
  from: _context11.t1
820
830
  };
821
831
  _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
- };
832
+ _context11.next = 30;
833
+ return this.res({
834
+ pid: pid,
835
+ mid: mid
836
+ });
829
837
  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;
838
+ res = _context11.sent;
839
+ hash = getHash(res);
840
+ _txmap = _defineProperty({}, mid, {
841
+ checked: false,
842
+ res: res
843
+ });
844
+ results.push({
845
+ mid: mid,
846
+ res: res
847
+ });
848
+ checked = false;
849
+ case 35:
850
+ _iterator5 = _createForOfIteratorHelper(_txs);
851
+ _context11.prev = 36;
852
+ _iterator5.s();
853
+ case 38:
854
+ if ((_step5 = _iterator5.n()).done) {
855
+ _context11.next = 52;
836
856
  break;
837
857
  }
838
- v = _step6.value;
858
+ v = _step5.value;
839
859
  if (_txmap[v.id].checked) {
840
- _context11.next = 46;
860
+ _context11.next = 50;
841
861
  break;
842
862
  }
843
863
  _txmap[v.id].checked = true;
844
864
  if (!(0, _ramda.isNil)(_txmap[v.id].res)) {
845
- _context11.next = 43;
865
+ _context11.next = 47;
846
866
  break;
847
867
  }
848
- _context11.next = 40;
868
+ _context11.next = 45;
849
869
  return this.res({
850
870
  pid: pid,
851
871
  mid: v.id
852
872
  });
853
- case 40:
873
+ case 45:
854
874
  _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
875
  _txmap[v.id].res = _res;
864
- case 43:
876
+ case 47:
865
877
  if (!(0, _ramda.isNil)(check) && check.length > 0) {
866
878
  checked = (0, _utils.allChecked)(check, _txmap[v.id].res, v.from);
867
879
  } else {
868
880
  checked = true;
869
881
  }
870
882
  if (!checked) {
871
- _context11.next = 46;
883
+ _context11.next = 50;
872
884
  break;
873
885
  }
874
- return _context11.abrupt("break", 48);
875
- case 46:
876
- _context11.next = 33;
886
+ return _context11.abrupt("break", 52);
887
+ case 50:
888
+ _context11.next = 38;
877
889
  break;
878
- case 48:
879
- _context11.next = 53;
890
+ case 52:
891
+ _context11.next = 57;
880
892
  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:
893
+ case 54:
894
+ _context11.prev = 54;
895
+ _context11.t3 = _context11["catch"](36);
896
+ _iterator5.e(_context11.t3);
897
+ case 57:
898
+ _context11.prev = 57;
899
+ _iterator5.f();
900
+ return _context11.finish(57);
901
+ case 60:
890
902
  if (!checked) {
891
- _context11.next = 58;
903
+ _context11.next = 62;
892
904
  break;
893
905
  }
894
- return _context11.abrupt("break", 63);
895
- case 58:
896
- _context11.next = 60;
906
+ return _context11.abrupt("break", 67);
907
+ case 62:
908
+ _context11.next = 64;
897
909
  return (0, _utils.wait)(1000);
898
- case 60:
899
- _context11.next = 62;
910
+ case 64:
911
+ _context11.next = 66;
900
912
  return getNewTxs(pid, _txs, _txmap);
901
- case 62:
913
+ case 66:
902
914
  if (Date.now() - start < timeout) {
903
- _context11.next = 30;
915
+ _context11.next = 35;
904
916
  break;
905
917
  }
906
- case 63:
918
+ case 67:
907
919
  if (checked) {
908
- _context11.next = 67;
920
+ _context11.next = 71;
909
921
  break;
910
922
  }
911
923
  err = "something went wrong!";
912
- _context11.next = 91;
924
+ _context11.next = 95;
913
925
  break;
914
- case 67:
926
+ case 71:
915
927
  _context11.t4 = _utils.mergeOut;
916
928
  _context11.t5 = out;
917
- _context11.next = 71;
929
+ _context11.next = 75;
918
930
  return checkOut(get, _txs, _txmap, out);
919
- case 71:
931
+ case 75:
920
932
  _context11.t6 = _context11.sent;
921
933
  _context11.t7 = get;
922
934
  out = (0, _context11.t4)(_context11.t5, _context11.t6, _context11.t7);
923
935
  if (!(!(0, _utils.isOutComplete)(out, get) && !(0, _ramda.isNil)(get))) {
924
- _context11.next = 91;
936
+ _context11.next = 95;
925
937
  break;
926
938
  }
927
- case 75:
939
+ case 79:
928
940
  if (!(Date.now() - start < timeout)) {
929
- _context11.next = 91;
941
+ _context11.next = 95;
930
942
  break;
931
943
  }
932
- _context11.next = 78;
944
+ _context11.next = 82;
933
945
  return getNewTxs(pid, _txs, _txmap);
934
- case 78:
946
+ case 82:
935
947
  _context11.t8 = _utils.mergeOut;
936
948
  _context11.t9 = out;
937
- _context11.next = 82;
949
+ _context11.next = 86;
938
950
  return checkOut(get, _txs, _txmap, out);
939
- case 82:
951
+ case 86:
940
952
  _context11.t10 = _context11.sent;
941
953
  _context11.t11 = get;
942
954
  out = (0, _context11.t8)(_context11.t9, _context11.t10, _context11.t11);
943
955
  if (!(0, _utils.isOutComplete)(out, get)) {
944
- _context11.next = 87;
956
+ _context11.next = 91;
945
957
  break;
946
958
  }
947
- return _context11.abrupt("break", 91);
948
- case 87:
949
- _context11.next = 89;
959
+ return _context11.abrupt("break", 95);
960
+ case 91:
961
+ _context11.next = 93;
950
962
  return (0, _utils.wait)(1000);
951
- case 89:
952
- _context11.next = 75;
963
+ case 93:
964
+ _context11.next = 79;
953
965
  break;
954
- case 91:
955
- _context11.next = 96;
966
+ case 95:
967
+ _context11.next = 100;
956
968
  break;
957
- case 93:
958
- _context11.prev = 93;
959
- _context11.t12 = _context11["catch"](15);
969
+ case 97:
970
+ _context11.prev = 97;
971
+ _context11.t12 = _context11["catch"](17);
960
972
  err = _context11.t12;
961
- case 96:
973
+ case 100:
962
974
  return _context11.abrupt("return", {
963
975
  mid: mid,
964
976
  res: res,
@@ -966,11 +978,11 @@ var AO = /*#__PURE__*/function () {
966
978
  out: out,
967
979
  results: results
968
980
  });
969
- case 97:
981
+ case 101:
970
982
  case "end":
971
983
  return _context11.stop();
972
984
  }
973
- }, _callee11, this, [[15, 93], [31, 50, 53, 56]]);
985
+ }, _callee11, this, [[17, 97], [36, 54, 57, 60]]);
974
986
  }));
975
987
  function msg(_x7) {
976
988
  return _msg.apply(this, arguments);
@@ -1433,7 +1445,7 @@ var AO = /*#__PURE__*/function () {
1433
1445
  key: "deploy",
1434
1446
  value: function () {
1435
1447
  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;
1448
+ 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
1449
  return _regeneratorRuntime().wrap(function _callee21$(_context21) {
1438
1450
  while (1) switch (_context21.prev = _context21.next) {
1439
1451
  case 0:
@@ -1485,14 +1497,14 @@ var AO = /*#__PURE__*/function () {
1485
1497
  }
1486
1498
  });
1487
1499
  i = 0;
1488
- _iterator7 = _createForOfIteratorHelper(!loads ? src_data ? [{
1500
+ _iterator6 = _createForOfIteratorHelper(!loads ? src_data ? [{
1489
1501
  data: src_data,
1490
1502
  src: src,
1491
1503
  fills: fills
1492
1504
  }] : [] : loads);
1493
1505
  try {
1494
- for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
1495
- v = _step7.value;
1506
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
1507
+ v = _step6.value;
1496
1508
  if (!isBoot || i !== 0) {
1497
1509
  args = v;
1498
1510
  if (typeof args === "string") args = {
@@ -1509,9 +1521,9 @@ var AO = /*#__PURE__*/function () {
1509
1521
  i++;
1510
1522
  }
1511
1523
  } catch (err) {
1512
- _iterator7.e(err);
1524
+ _iterator6.e(err);
1513
1525
  } finally {
1514
- _iterator7.f();
1526
+ _iterator6.f();
1515
1527
  }
1516
1528
  _context21.next = 9;
1517
1529
  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,
@@ -52,15 +53,21 @@ import {
52
53
  optAO,
53
54
  } from "./utils.js"
54
55
 
56
+ const getHash = res =>
57
+ md5(
58
+ JSON.stringify({
59
+ Messages: res.Messages ?? [],
60
+ Spawns: res.Spawns ?? [],
61
+ Assignments: res.Assignments ?? [],
62
+ }),
63
+ )
64
+
55
65
  function createDataItemSigner2(wallet) {
56
66
  const signer = async ({ data, tags, target, anchor }) => {
57
67
  const signer = new ArweaveSigner(wallet)
58
68
  const dataItem = createData(data, signer, { tags, target, anchor })
59
69
  const sig = dataItem.sign(signer).then(async () => {
60
- return {
61
- id: await dataItem.id,
62
- raw: await dataItem.getRaw(),
63
- }
70
+ return { id: await dataItem.id, raw: await dataItem.getRaw() }
64
71
  })
65
72
  return sig
66
73
  }
@@ -386,35 +393,44 @@ class AO {
386
393
  get,
387
394
  timeout = 0,
388
395
  mode = "aoconnect",
396
+ limit = 25,
389
397
  }) {
390
398
  let err = null
391
399
  ;({ jwk, err } = await this.ar.checkWallet({ jwk }))
392
400
  if (err) return { err }
393
401
  let anchors = {}
402
+ let hash = null
403
+ let mid = null
394
404
  const getNewTxs = async (pid, _txs, _txmap) => {
405
+ let exists = false
395
406
  if (mode === "gql") {
396
407
  const txs = await this.ar.gql.txs({
397
408
  recipient: pid,
409
+ limit,
398
410
  fields: ["id", "recipient", "tags", { owner: ["address"] }],
399
411
  })
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"] }
412
+ for (const v of reverse(txs)) {
413
+ if (v.id === mid) exists = true
414
+ else if (exists) {
415
+ if (isNil(_txmap[v.id])) {
416
+ const t = ltags(v.tags)
417
+ if (t.type === "Message") {
418
+ v.from = t["from-process"] ?? v.owner?.address
419
+ _txs.unshift(v)
420
+ _txmap[v.id] = { checked: false, ref: t["x-reference"] }
421
+ }
407
422
  }
408
423
  }
409
424
  }
410
425
  } 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)
426
+ for (let v of reverse(await this.res({ pid, limit }))) {
427
+ const hash2 = getHash(v)
428
+ if (!exists) {
429
+ if (hash2 === hash) exists = true
430
+ } else {
431
+ if (isNil(_txmap[v.cursor + pid])) {
432
+ _txmap[v.cursor + pid] = { checked: false, res: v }
433
+ _txs.unshift({ id: v.cursor + pid })
418
434
  }
419
435
  }
420
436
  }
@@ -424,6 +440,7 @@ class AO {
424
440
  for (let v of _txs) {
425
441
  if (isNil(_txmap[v.id].res)) {
426
442
  const res = await this.res({ pid, mid: v.id })
443
+ if (!hash) console.log(res)
427
444
  _txmap[v.id].res = res
428
445
  }
429
446
  if (!isNil(_txmap[v.id].res) && _txmap[v.id].out !== true) {
@@ -435,7 +452,7 @@ class AO {
435
452
  }
436
453
  return out
437
454
  }
438
- let [res, out, mid, results] = [null, null, null, []]
455
+ let [res, out, results] = [null, null, []]
439
456
  let _tags = buildTags(act, tags)
440
457
  let start = Date.now()
441
458
  try {
@@ -447,21 +464,17 @@ class AO {
447
464
  })
448
465
  if (!is(Array, check)) check = [check]
449
466
  let _txs = [{ id: mid, from: await this.ar.toAddr(jwk) }]
450
- let _txmap = {}
451
- const t = ltags(_tags)
467
+ res = await this.res({ pid, mid })
468
+ hash = getHash(res)
469
+ let _txmap = { [mid]: { checked: false, res } }
470
+ results.push({ mid, res })
452
471
  let checked = false
453
- _txmap[mid] = { checked: false, ref: t["x-reference"] }
454
472
  do {
455
473
  for (let v of _txs) {
456
474
  if (!_txmap[v.id].checked) {
457
475
  _txmap[v.id].checked = true
458
476
  if (isNil(_txmap[v.id].res)) {
459
477
  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
478
  _txmap[v.id].res = _res
466
479
  }
467
480
  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.8",
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",